Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

github.com/thorsphere/lpcode

Package Overview
Dependencies
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/thorsphere/lpcode - go Package Compare versions

Comparing version
v1.1.1
to
v1.1.2
+7
-1
README.md

@@ -76,3 +76,2 @@ # lpcode

func (code *Code) KeyedElement(a *KeyedElementArgs) *Code
func (code *Code) TestVarDecl(tv []TestVar) *Code
func (code *Code) Format() error

@@ -82,2 +81,9 @@ func (code *Code) String() string

The package includes support for generating test variable declarations through the TestVarDecl method. Test variables are predefined values with associated types and names that can be reused across multiple test cases to ensure consistency. The FindTestVar helper function allows you to retrieve a specific test variable by its type from an array of TestVar structs.
```go
func (code *Code) TestVarDecl(tv []TestVar) *Code
func FindTestVar(t string, tv []TestVar) (*TestVar, error)
```
## Example

@@ -84,0 +90,0 @@

@@ -6,4 +6,8 @@ // Copyright (c) 2023-2026 thorsphere.

import "fmt"
import (
"fmt" // fmt
"github.com/thorsphere/tserr" // tserr
)
type TestVar struct {

@@ -47,1 +51,23 @@ T string // type of testvariable

}
// findTestVar is a helper function that takes t as a string representing a type, iterates
// through the array of TestVar structs tv, and checks if the type of any TestVar matches t.
// It returns a pointer to the corresponding TestVar struct for that type.
// It returns nil and an error if the type is not found in the predefined test cases
// or if there is an issue with the input.
func FindTestVar(t string, tv []TestVar) (*TestVar, error) {
// Return nil and an error in case tv is nil
if tv == nil {
return nil, tserr.NilPtr()
}
// Iterate over testvars and return the one that matches the type t
for _, v := range tv {
// Check if the type of the current TestVar matches t
if v.T == t {
// If a match is found, return a pointer to the corresponding TestVar struct
return &v, nil
}
}
// Return nil and an error if the type is not found in the predefined test variables
return nil, tserr.NotExistent(fmt.Sprintf("test variable of type %v", t))
}