github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/define_marshal_test.go (about) 1 package lang_test 2 3 import ( 4 "testing" 5 6 _ "github.com/lmorg/murex/builtins" 7 "github.com/lmorg/murex/lang" 8 "github.com/lmorg/murex/lang/types" 9 "github.com/lmorg/murex/test/count" 10 ) 11 12 func TestMarshalArrayJsonString(t *testing.T) { 13 count.Tests(t, 1) 14 15 input := []string{"e", "d", "c", "b", "a"} // lets prove the output retains sorting 16 output := `["e","d","c","b","a"]` 17 18 lang.InitEnv() 19 fork := lang.ShellProcess.Fork(lang.F_NO_STDIN | lang.F_NO_STDOUT | lang.F_NO_STDERR) 20 21 b, err := lang.MarshalData(fork.Process, types.Json, input) 22 if err != nil { 23 t.Error(err) 24 return 25 } 26 27 if string(b) != output { 28 t.Error("Marshaller output doesn't match expected:") 29 t.Logf(" Input: %v", input) 30 t.Logf(" Expected: '%s'", output) 31 t.Logf(" Actual: '%s'", b) 32 } 33 } 34 35 func TestMarshalArrayJsonInt(t *testing.T) { 36 count.Tests(t, 1) 37 38 input := []int{5, 4, 3, 2, 1} // lets prove the output retains sorting 39 output := `[5,4,3,2,1]` 40 41 lang.InitEnv() 42 fork := lang.ShellProcess.Fork(lang.F_NO_STDIN | lang.F_NO_STDOUT | lang.F_NO_STDERR) 43 44 b, err := lang.MarshalData(fork.Process, types.Json, input) 45 if err != nil { 46 t.Error(err) 47 return 48 } 49 50 if string(b) != output { 51 t.Error("Marshaller output doesn't match expected:") 52 t.Logf(" Input: %v", input) 53 t.Logf(" Expected: '%s'", output) 54 t.Logf(" Actual: '%s'", b) 55 } 56 }