aboutsummaryrefslogtreecommitdiff
path: root/parser/parser_test.go
diff options
context:
space:
mode:
authorNeonXP <i@neonxp.dev>2022-11-16 05:11:19 +0300
committerNeonXP <i@neonxp.dev>2022-11-16 05:11:19 +0300
commita321bfe7b2f6db5078de7b2e5ed5ddcccd65f319 (patch)
treed11c187bceee610a7843463949df128569142680 /parser/parser_test.go
initial commit
Diffstat (limited to 'parser/parser_test.go')
-rw-r--r--parser/parser_test.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/parser/parser_test.go b/parser/parser_test.go
new file mode 100644
index 0000000..ea5aa0e
--- /dev/null
+++ b/parser/parser_test.go
@@ -0,0 +1,71 @@
+package parser
+
+import (
+ "reflect"
+ "testing"
+
+ "go.neonxp.dev/json/model"
+)
+
+func TestParse(t *testing.T) {
+ type args struct {
+ json string
+ }
+ tests := []struct {
+ name string
+ args args
+ want *model.Node
+ wantErr bool
+ }{
+ {
+ name: "complex",
+ args: args{
+ json: `{
+ "string key": "string value",
+ "number key": 1337,
+ "float key": 123.3,
+ "object key": {
+ "ab": "cd"
+ },
+ "array key": [
+ 1,
+ 2,
+ "three"
+ ],
+ "null key":null,
+ "boolean key":true
+ }`,
+ },
+ want: model.NewNode(
+ model.NodeObjectValue{
+ "string key": model.NewNode("string value"),
+ "number key": model.NewNode(1337),
+ "float key": model.NewNode(123.3),
+ "object key": model.NewNode(model.NodeObjectValue{
+ "ab": model.NewNode("cd"),
+ }),
+ "array key": model.NewNode(model.NodeArrayValue{
+ model.NewNode(1),
+ model.NewNode(2),
+ model.NewNode("three"),
+ }),
+ "null key": model.NewNode(nil),
+ "boolean key": model.NewNode(true),
+ },
+ ),
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, err := Parse(tt.args.json)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Parse() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}