Skip to content

Commit

Permalink
Covert package tests " -> `
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelS11 committed Mar 21, 2018
1 parent 468a73e commit 504bb35
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions packages/encoding.json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ func TestJson(t *testing.T) {
os.Setenv("ANKO_DEBUG", "1")
var toByteSlice = func(s string) []byte { return []byte(s) }
tests := []testStruct{
{script: "json = import(\"encoding/json\"); a = {\"b\": \"b\"}; c, err = json.Marshal(a); err", output: map[string]interface{}{"a": map[string]interface{}{"b": "b"}, "c": []byte("{\"b\":\"b\"}")}},
{script: "json = import(\"encoding/json\"); b = 1; err = json.Unmarshal(a, &b); err", input: map[string]interface{}{"a": []byte("{\"b\": \"b\"}")}, output: map[string]interface{}{"a": []byte("{\"b\": \"b\"}"), "b": map[string]interface{}{"b": "b"}}},
{script: "json = import(\"encoding/json\"); b = 1; err = json.Unmarshal(toByteSlice(a), &b); err", input: map[string]interface{}{"a": "{\"b\": \"b\"}", "toByteSlice": toByteSlice}, output: map[string]interface{}{"a": "{\"b\": \"b\"}", "b": map[string]interface{}{"b": "b"}}},
{script: "json = import(\"encoding/json\"); b = 1; err = json.Unmarshal(toByteSlice(a), &b); err", input: map[string]interface{}{"a": "[[\"1\", \"2\"],[\"3\", \"4\"]]", "toByteSlice": toByteSlice}, output: map[string]interface{}{"a": "[[\"1\", \"2\"],[\"3\", \"4\"]]", "b": []interface{}{[]interface{}{"1", "2"}, []interface{}{"3", "4"}}}},
{script: `json = import("encoding/json"); a = {"b": "b"}; c, err = json.Marshal(a); err`, output: map[string]interface{}{"a": map[string]interface{}{"b": "b"}, "c": []byte("{\"b\":\"b\"}")}},
{script: `json = import("encoding/json"); b = 1; err = json.Unmarshal(a, &b); err`, input: map[string]interface{}{"a": []byte("{\"b\": \"b\"}")}, output: map[string]interface{}{"a": []byte("{\"b\": \"b\"}"), "b": map[string]interface{}{"b": "b"}}},
{script: `json = import("encoding/json"); b = 1; err = json.Unmarshal(toByteSlice(a), &b); err`, input: map[string]interface{}{"a": "{\"b\": \"b\"}", "toByteSlice": toByteSlice}, output: map[string]interface{}{"a": "{\"b\": \"b\"}", "b": map[string]interface{}{"b": "b"}}},
{script: `json = import("encoding/json"); b = 1; err = json.Unmarshal(toByteSlice(a), &b); err`, input: map[string]interface{}{"a": "[[\"1\", \"2\"],[\"3\", \"4\"]]", "toByteSlice": toByteSlice}, output: map[string]interface{}{"a": "[[\"1\", \"2\"],[\"3\", \"4\"]]", "b": []interface{}{[]interface{}{"1", "2"}, []interface{}{"3", "4"}}}},
}
runTests(t, tests)
}
4 changes: 2 additions & 2 deletions packages/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type testStruct struct {
func TestDefineImport(t *testing.T) {
env := vm.NewEnv()
DefineImport(env)
value, err := env.Execute("strings = import(\"strings\"); strings.ToLower(\"TEST\")")
value, err := env.Execute(`strings = import("strings"); strings.ToLower("TEST")`)
if err != nil {
t.Errorf("Execute error - received: %v - expected: %v", err, nil)
}
Expand All @@ -35,7 +35,7 @@ func TestDefineImportPackageNotFound(t *testing.T) {
os.Unsetenv("ANKO_DEBUG")
env := vm.NewEnv()
DefineImport(env)
value, err := env.Execute("a = import(\"a\")")
value, err := env.Execute(`a = import("a")`)
expectedError := ("package 'a' not found")
if err == nil {
t.Errorf("DefineImportPackageNotFound error - received: %v - expected: %v", err, expectedError)
Expand Down
32 changes: 16 additions & 16 deletions packages/regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ import (
func TestRegexp(t *testing.T) {
os.Setenv("ANKO_DEBUG", "1")
tests := []testStruct{
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(\"^simple$\"); re.MatchString(\"simple\")", runOutput: true},
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(\"^simple$\"); re.MatchString(\"no match\")", runOutput: false},
{script: `regexp = import("regexp"); re = regexp.MustCompile("^simple$"); re.MatchString("simple")`, runOutput: true},
{script: `regexp = import("regexp"); re = regexp.MustCompile("^simple$"); re.MatchString("no match")`, runOutput: false},

{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(a); re.MatchString(b)", input: map[string]interface{}{"a": "^simple$", "b": "simple"}, runOutput: true, output: map[string]interface{}{"a": "^simple$", "b": "simple"}},
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(a); re.MatchString(b)", input: map[string]interface{}{"a": "^simple$", "b": "no match"}, runOutput: false, output: map[string]interface{}{"a": "^simple$", "b": "no match"}},
{script: `regexp = import("regexp"); re = regexp.MustCompile(a); re.MatchString(b)`, input: map[string]interface{}{"a": "^simple$", "b": "simple"}, runOutput: true, output: map[string]interface{}{"a": "^simple$", "b": "simple"}},
{script: `regexp = import("regexp"); re = regexp.MustCompile(a); re.MatchString(b)`, input: map[string]interface{}{"a": "^simple$", "b": "no match"}, runOutput: false, output: map[string]interface{}{"a": "^simple$", "b": "no match"}},

{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(\"^a\\\\.\\\\d+\\\\.b$\"); re.String()", runOutput: "^a\\.\\d+\\.b$"},
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(\"^a\\\\.\\\\d+\\\\.b$\"); re.MatchString(\"a.1.b\")", runOutput: true},
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(\"^a\\\\.\\\\d+\\\\.b$\"); re.MatchString(\"a.22.b\")", runOutput: true},
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(\"^a\\\\.\\\\d+\\\\.b$\"); re.MatchString(\"a.333.b\")", runOutput: true},
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(\"^a\\\\.\\\\d+\\\\.b$\"); re.MatchString(\"no match\")", runOutput: false},
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(\"^a\\\\.\\\\d+\\\\.b$\"); re.MatchString(\"a+1+b\")", runOutput: false},
{script: `regexp = import("regexp"); re = regexp.MustCompile("^a\\.\\d+\\.b$"); re.String()`, runOutput: "^a\\.\\d+\\.b$"},
{script: `regexp = import("regexp"); re = regexp.MustCompile("^a\\.\\d+\\.b$"); re.MatchString("a.1.b")`, runOutput: true},
{script: `regexp = import("regexp"); re = regexp.MustCompile("^a\\.\\d+\\.b$"); re.MatchString("a.22.b")`, runOutput: true},
{script: `regexp = import("regexp"); re = regexp.MustCompile("^a\\.\\d+\\.b$"); re.MatchString("a.333.b")`, runOutput: true},
{script: `regexp = import("regexp"); re = regexp.MustCompile("^a\\.\\d+\\.b$"); re.MatchString("no match")`, runOutput: false},
{script: `regexp = import("regexp"); re = regexp.MustCompile("^a\\.\\d+\\.b$"); re.MatchString("a+1+b")`, runOutput: false},

{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(a); re.String()", input: map[string]interface{}{"a": "^a\\.\\d+\\.b$"}, runOutput: "^a\\.\\d+\\.b$", output: map[string]interface{}{"a": "^a\\.\\d+\\.b$"}},
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(a); re.MatchString(b)", input: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a.1.b"}, runOutput: true, output: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a.1.b"}},
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(a); re.MatchString(b)", input: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a.22.b"}, runOutput: true, output: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a.22.b"}},
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(a); re.MatchString(b)", input: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a.333.b"}, runOutput: true, output: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a.333.b"}},
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(a); re.MatchString(b)", input: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "no match"}, runOutput: false, output: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "no match"}},
{script: "regexp = import(\"regexp\"); re = regexp.MustCompile(a); re.MatchString(b)", input: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a+1+b"}, runOutput: false, output: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a+1+b"}},
{script: `regexp = import("regexp"); re = regexp.MustCompile(a); re.String()`, input: map[string]interface{}{"a": "^a\\.\\d+\\.b$"}, runOutput: "^a\\.\\d+\\.b$", output: map[string]interface{}{"a": "^a\\.\\d+\\.b$"}},
{script: `regexp = import("regexp"); re = regexp.MustCompile(a); re.MatchString(b)`, input: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a.1.b"}, runOutput: true, output: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a.1.b"}},
{script: `regexp = import("regexp"); re = regexp.MustCompile(a); re.MatchString(b)`, input: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a.22.b"}, runOutput: true, output: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a.22.b"}},
{script: `regexp = import("regexp"); re = regexp.MustCompile(a); re.MatchString(b)`, input: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a.333.b"}, runOutput: true, output: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a.333.b"}},
{script: `regexp = import("regexp"); re = regexp.MustCompile(a); re.MatchString(b)`, input: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "no match"}, runOutput: false, output: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "no match"}},
{script: `regexp = import("regexp"); re = regexp.MustCompile(a); re.MatchString(b)`, input: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a+1+b"}, runOutput: false, output: map[string]interface{}{"a": "^a\\.\\d+\\.b$", "b": "a+1+b"}},
}
runTests(t, tests)
}
6 changes: 3 additions & 3 deletions packages/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
func TestSort(t *testing.T) {
os.Setenv("ANKO_DEBUG", "1")
tests := []testStruct{
{script: "sort = import(\"sort\"); a = make([]int); a += [5, 3, 1, 4, 2]; sort.Ints(a); a", runOutput: []int{1, 2, 3, 4, 5}, output: map[string]interface{}{"a": []int{1, 2, 3, 4, 5}}},
{script: "sort = import(\"sort\"); a = make([]float64); a += [5.5, 3.3, 1.1, 4.4, 2.2]; sort.Float64s(a); a", runOutput: []float64{1.1, 2.2, 3.3, 4.4, 5.5}, output: map[string]interface{}{"a": []float64{1.1, 2.2, 3.3, 4.4, 5.5}}},
{script: "sort = import(\"sort\"); a = make([]string); a += [\"e\", \"c\", \"a\", \"d\", \"b\"]; sort.Strings(a); a", runOutput: []string{"a", "b", "c", "d", "e"}, output: map[string]interface{}{"a": []string{"a", "b", "c", "d", "e"}}},
{script: `sort = import("sort"); a = make([]int); a += [5, 3, 1, 4, 2]; sort.Ints(a); a`, runOutput: []int{1, 2, 3, 4, 5}, output: map[string]interface{}{"a": []int{1, 2, 3, 4, 5}}},
{script: `sort = import("sort"); a = make([]float64); a += [5.5, 3.3, 1.1, 4.4, 2.2]; sort.Float64s(a); a`, runOutput: []float64{1.1, 2.2, 3.3, 4.4, 5.5}, output: map[string]interface{}{"a": []float64{1.1, 2.2, 3.3, 4.4, 5.5}}},
{script: `sort = import("sort"); a = make([]string); a += ["e", "c", "a", "d", "b"]; sort.Strings(a); a`, runOutput: []string{"a", "b", "c", "d", "e"}, output: map[string]interface{}{"a": []string{"a", "b", "c", "d", "e"}}},
{script: `
sort = import("sort")
a = [5, 1.1, 3, "f", "2", "4.4"]
Expand Down
26 changes: 13 additions & 13 deletions packages/strconv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ func TestStrconv(t *testing.T) {
return fmt.Sprint(v)
}
tests := []testStruct{
{script: "strconv = import(\"strconv\"); a = true; b = strconv.FormatBool(a)", runOutput: "true", output: map[string]interface{}{"a": true, "b": "true"}},
{script: "strconv = import(\"strconv\"); a = 1.1; b = strconv.FormatFloat(a, toRune(\"f\"), -1, 64)", input: map[string]interface{}{"toRune": toRune}, runOutput: "1.1", output: map[string]interface{}{"a": float64(1.1), "b": "1.1"}},
{script: "strconv = import(\"strconv\"); a = 1; b = strconv.FormatInt(a, 10)", runOutput: "1", output: map[string]interface{}{"a": int64(1), "b": "1"}},
{script: "strconv = import(\"strconv\"); b = strconv.FormatInt(a, 10)", input: map[string]interface{}{"a": uint64(1)}, runOutput: "1", output: map[string]interface{}{"a": uint64(1), "b": "1"}},
{script: `strconv = import("strconv"); a = true; b = strconv.FormatBool(a)`, runOutput: "true", output: map[string]interface{}{"a": true, "b": "true"}},
{script: `strconv = import("strconv"); a = 1.1; b = strconv.FormatFloat(a, toRune("f"), -1, 64)`, input: map[string]interface{}{"toRune": toRune}, runOutput: "1.1", output: map[string]interface{}{"a": float64(1.1), "b": "1.1"}},
{script: `strconv = import("strconv"); a = 1; b = strconv.FormatInt(a, 10)`, runOutput: "1", output: map[string]interface{}{"a": int64(1), "b": "1"}},
{script: `strconv = import("strconv"); b = strconv.FormatInt(a, 10)`, input: map[string]interface{}{"a": uint64(1)}, runOutput: "1", output: map[string]interface{}{"a": uint64(1), "b": "1"}},

{script: "strconv = import(\"strconv\"); a = \"true\"; b, err = strconv.ParseBool(a); err = toString(err)", input: map[string]interface{}{"toString": toString}, runOutput: "<nil>", output: map[string]interface{}{"a": "true", "b": true, "err": "<nil>"}},
{script: "strconv = import(\"strconv\"); a = \"2\"; b, err = strconv.ParseBool(a); err = toString(err)", input: map[string]interface{}{"toString": toString}, runOutput: "strconv.ParseBool: parsing \"2\": invalid syntax", output: map[string]interface{}{"a": "2", "b": false, "err": "strconv.ParseBool: parsing \"2\": invalid syntax"}},
{script: "strconv = import(\"strconv\"); a = \"1.1\"; b, err = strconv.ParseFloat(a, 64); err = toString(err)", input: map[string]interface{}{"toString": toString}, runOutput: "<nil>", output: map[string]interface{}{"a": "1.1", "b": float64(1.1), "err": "<nil>"}},
{script: "strconv = import(\"strconv\"); a = \"a\"; b, err = strconv.ParseFloat(a, 64); err = toString(err)", input: map[string]interface{}{"toString": toString}, runOutput: "strconv.ParseFloat: parsing \"a\": invalid syntax", output: map[string]interface{}{"a": "a", "b": float64(0), "err": "strconv.ParseFloat: parsing \"a\": invalid syntax"}},
{script: "strconv = import(\"strconv\"); a = \"1\"; b, err = strconv.ParseInt(a, 10, 64); err = toString(err)", input: map[string]interface{}{"toString": toString}, runOutput: "<nil>", output: map[string]interface{}{"a": "1", "b": int64(1), "err": "<nil>"}},
{script: "strconv = import(\"strconv\"); a = \"1.1\"; b, err = strconv.ParseInt(a, 10, 64); err = toString(err)", input: map[string]interface{}{"toString": toString}, runOutput: "strconv.ParseInt: parsing \"1.1\": invalid syntax", output: map[string]interface{}{"a": "1.1", "b": int64(0), "err": "strconv.ParseInt: parsing \"1.1\": invalid syntax"}},
{script: "strconv = import(\"strconv\"); a = \"a\"; b, err = strconv.ParseInt(a, 10, 64); err = toString(err)", input: map[string]interface{}{"toString": toString}, runOutput: "strconv.ParseInt: parsing \"a\": invalid syntax", output: map[string]interface{}{"a": "a", "b": int64(0), "err": "strconv.ParseInt: parsing \"a\": invalid syntax"}},
{script: "strconv = import(\"strconv\"); a = \"1\"; b, err = strconv.ParseUint(a, 10, 64); err = toString(err)", input: map[string]interface{}{"toString": toString}, runOutput: "<nil>", output: map[string]interface{}{"a": "1", "b": uint64(1), "err": "<nil>"}},
{script: "strconv = import(\"strconv\"); a = \"a\"; b, err = strconv.ParseUint(a, 10, 64); err = toString(err)", input: map[string]interface{}{"toString": toString}, runOutput: "strconv.ParseUint: parsing \"a\": invalid syntax", output: map[string]interface{}{"a": "a", "b": uint64(0), "err": "strconv.ParseUint: parsing \"a\": invalid syntax"}},
{script: `strconv = import("strconv"); a = "true"; b, err = strconv.ParseBool(a); err = toString(err)`, input: map[string]interface{}{"toString": toString}, runOutput: "<nil>", output: map[string]interface{}{"a": "true", "b": true, "err": "<nil>"}},
{script: `strconv = import("strconv"); a = "2"; b, err = strconv.ParseBool(a); err = toString(err)`, input: map[string]interface{}{"toString": toString}, runOutput: `strconv.ParseBool: parsing "2": invalid syntax`, output: map[string]interface{}{"a": "2", "b": false, "err": `strconv.ParseBool: parsing "2": invalid syntax`}},
{script: `strconv = import("strconv"); a = "1.1"; b, err = strconv.ParseFloat(a, 64); err = toString(err)`, input: map[string]interface{}{"toString": toString}, runOutput: "<nil>", output: map[string]interface{}{"a": "1.1", "b": float64(1.1), "err": "<nil>"}},
{script: `strconv = import("strconv"); a = "a"; b, err = strconv.ParseFloat(a, 64); err = toString(err)`, input: map[string]interface{}{"toString": toString}, runOutput: `strconv.ParseFloat: parsing "a": invalid syntax`, output: map[string]interface{}{"a": "a", "b": float64(0), "err": `strconv.ParseFloat: parsing "a": invalid syntax`}},
{script: `strconv = import("strconv"); a = "1"; b, err = strconv.ParseInt(a, 10, 64); err = toString(err)`, input: map[string]interface{}{"toString": toString}, runOutput: "<nil>", output: map[string]interface{}{"a": "1", "b": int64(1), "err": "<nil>"}},
{script: `strconv = import("strconv"); a = "1.1"; b, err = strconv.ParseInt(a, 10, 64); err = toString(err)`, input: map[string]interface{}{"toString": toString}, runOutput: `strconv.ParseInt: parsing "1.1": invalid syntax`, output: map[string]interface{}{"a": "1.1", "b": int64(0), "err": `strconv.ParseInt: parsing "1.1": invalid syntax`}},
{script: `strconv = import("strconv"); a = "a"; b, err = strconv.ParseInt(a, 10, 64); err = toString(err)`, input: map[string]interface{}{"toString": toString}, runOutput: `strconv.ParseInt: parsing "a": invalid syntax`, output: map[string]interface{}{"a": "a", "b": int64(0), "err": `strconv.ParseInt: parsing "a": invalid syntax`}},
{script: `strconv = import("strconv"); a = "1"; b, err = strconv.ParseUint(a, 10, 64); err = toString(err)`, input: map[string]interface{}{"toString": toString}, runOutput: "<nil>", output: map[string]interface{}{"a": "1", "b": uint64(1), "err": "<nil>"}},
{script: `strconv = import("strconv"); a = "a"; b, err = strconv.ParseUint(a, 10, 64); err = toString(err)`, input: map[string]interface{}{"toString": toString}, runOutput: `strconv.ParseUint: parsing "a": invalid syntax`, output: map[string]interface{}{"a": "a", "b": uint64(0), "err": `strconv.ParseUint: parsing "a": invalid syntax`}},
}
runTests(t, tests)
}
6 changes: 3 additions & 3 deletions packages/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
func TestStrings(t *testing.T) {
os.Setenv("ANKO_DEBUG", "1")
tests := []testStruct{
{script: "strings = import(\"strings\"); a = \" one two \"; b = strings.TrimSpace(a)", runOutput: "one two", output: map[string]interface{}{"a": " one two ", "b": "one two"}},
{script: "strings = import(\"strings\"); a = \"a b c d\"; b = strings.Split(a, \" \")", runOutput: []string{"a", "b", "c", "d"}, output: map[string]interface{}{"a": "a b c d", "b": []string{"a", "b", "c", "d"}}},
{script: "strings = import(\"strings\"); a = \"a b c d\"; b = strings.SplitN(a, \" \", 3)", runOutput: []string{"a", "b", "c d"}, output: map[string]interface{}{"a": "a b c d", "b": []string{"a", "b", "c d"}}},
{script: `strings = import("strings"); a = " one two "; b = strings.TrimSpace(a)`, runOutput: "one two", output: map[string]interface{}{"a": " one two ", "b": "one two"}},
{script: `strings = import("strings"); a = "a b c d"; b = strings.Split(a, " ")`, runOutput: []string{"a", "b", "c", "d"}, output: map[string]interface{}{"a": "a b c d", "b": []string{"a", "b", "c", "d"}}},
{script: `strings = import("strings"); a = "a b c d"; b = strings.SplitN(a, " ", 3)`, runOutput: []string{"a", "b", "c d"}, output: map[string]interface{}{"a": "a b c d", "b": []string{"a", "b", "c d"}}},
}
runTests(t, tests)
}

0 comments on commit 504bb35

Please sign in to comment.