tests

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SampleOperations = map[string]map[string]interface{}{

	"add1": {
		"op":    "add",
		"path":  "",
		"value": nil,
	},
	"add2": {
		"op":    "add",
		"path":  "/foo",
		"value": 123,
	},
	"add3": {
		"op":    "add",
		"path":  "",
		"value": false,
	},
	"add4": {
		"op":   "add",
		"path": "/mentions/2",
		"value": map[string]interface{}{
			"id":   "1234",
			"name": "Joe Jones",
		},
	},
	"add5": {
		"op":   "add",
		"path": "/mentions/2/-",
		"value": map[string]interface{}{
			"id":   "1234",
			"name": "Joe Jones",
		},
	},
	"add6": {
		"op":    "add",
		"path":  "",
		"value": map[string]interface{}{},
	},
	"add7": {
		"op":    "add",
		"path":  "/5/a",
		"value": []interface{}{1, nil, "3"},
	},

	"remove1": {
		"op":   "remove",
		"path": "",
	},
	"remove2": {
		"op":   "remove",
		"path": "/a/b/c/d/e",
	},
	"remove3": {
		"op":       "remove",
		"path":     "/a/b/c/d/e/-",
		"oldValue": nil,
	},
	"remove4": {
		"op":   "remove",
		"path": "/user/123/name",
		"oldValue": map[string]interface{}{
			"firstName": "John",
			"lastName":  "Notjohn",
		},
	},

	"replace1": {
		"op":    "replace",
		"path":  "/a",
		"value": "asdf",
	},
	"replace2": {
		"op":    "replace",
		"path":  "/a/b/c",
		"value": 123,
	},
	"replace3": {
		"op":   "replace",
		"path": "/a/1/-",
		"value": map[string]interface{}{
			"foo": "qux",
		},
		"oldValue": map[string]interface{}{
			"foo": "bar",
		},
	},

	"copy1": {
		"op":   "copy",
		"path": "/foo/bar",
		"from": "/foo/quz",
	},
	"copy2": {
		"op":   "copy",
		"path": "",
		"from": "",
	},
	"copy3": {
		"op":   "copy",
		"path": "/",
		"from": "",
	},
	"copy4": {
		"op":   "copy",
		"path": "/",
		"from": "/a/b/1/2/-",
	},

	"move1": {
		"op":   "move",
		"path": "",
		"from": "",
	},
	"move2": {
		"op":   "move",
		"path": "/a/b/",
		"from": "/c/d/0",
	},

	"test1": {
		"op":    "test",
		"path":  "",
		"value": nil,
	},
	"test2": {
		"op":    "test",
		"path":  "/ha/hi",
		"value": map[string]interface{}{"foo": "bar"},
	},
	"test3": {
		"op":    "test",
		"path":  "/ha/1/2",
		"value": []interface{}{1, map[string]interface{}{"a": false}, "null"},
	},

	"defined1": {
		"op":   "defined",
		"path": "",
	},
	"defined2": {
		"op":   "defined",
		"path": "/1",
	},
	"defined3": {
		"op":   "defined",
		"path": "/foo",
	},

	"undefined1": {
		"op":   "undefined",
		"path": "/a/abc",
	},
	"undefined2": {
		"op":   "undefined",
		"path": "/",
	},
	"undefined3": {
		"op":   "undefined",
		"path": "/1",
	},

	"test_type1": {
		"op":   "test_type",
		"path": "",
		"type": []string{"array"},
	},
	"test_type2": {
		"op":   "test_type",
		"path": "/a/1",
		"type": []string{"integer", "boolean"},
	},
	"test_type3": {
		"op":   "test_type",
		"path": "/a/b/c",
		"type": []string{"array", "boolean", "integer", "null", "number", "object", "string"},
	},

	"test_string1": {
		"op":   "test_string",
		"path": "/a/b/c",
		"pos":  0,
		"str":  "asdf",
	},
	"test_string2": {
		"op":   "test_string",
		"path": "/a/1",
		"pos":  4,
		"str":  "",
	},

	"test_string_len1": {
		"op":   "test_string_len",
		"path": "/",
		"len":  123,
	},
	"test_string_len2": {
		"op":   "test_string_len",
		"path": "/a/bb/ccc",
		"len":  5,
		"not":  true,
	},

	"contains1": {
		"op":    "contains",
		"path":  "/a",
		"value": "",
	},
	"contains2": {
		"op":    "contains",
		"path":  "",
		"value": "asdf",
	},

	"matches1": {
		"op":    "matches",
		"path":  "/gg",
		"value": "a",
	},

	"ends1": {
		"op":    "ends",
		"path":  "/foo",
		"value": "",
	},
	"ends2": {
		"op":    "ends",
		"path":  "/",
		"value": "asdf",
	},
	"ends3": {
		"op":          "ends",
		"path":        "/",
		"value":       "asdf",
		"ignore_case": true,
	},

	"starts1": {
		"op":    "starts",
		"path":  "/foo",
		"value": "",
	},
	"starts2": {
		"op":    "starts",
		"path":  "/foo",
		"value": "aa",
	},
	"starts3": {
		"op":          "starts",
		"path":        "/foo",
		"value":       "aa",
		"ignore_case": true,
	},

	"type1": {
		"op":    "type",
		"path":  "/1/2/3",
		"value": "array",
	},
	"type2": {
		"op":    "type",
		"path":  "/1/2/3",
		"value": "boolean",
	},
	"type3": {
		"op":    "type",
		"path":  "/1/2/3",
		"value": "integer",
	},
	"type4": {
		"op":    "type",
		"path":  "/1/2/3",
		"value": "null",
	},
	"type5": {
		"op":    "type",
		"path":  "/1/2/3",
		"value": "number",
	},
	"type6": {
		"op":    "type",
		"path":  "/1/2/3",
		"value": "object",
	},
	"type7": {
		"op":    "type",
		"path":  "/1/2/3",
		"value": "string",
	},

	"in1": {
		"op":    "in",
		"path":  "/",
		"value": []interface{}{"asdf"},
	},
	"in2": {
		"op":    "in",
		"path":  "/foo/bar",
		"value": []interface{}{"asdf", 132, map[string]interface{}{"a": "b"}, nil},
	},

	"less1": {
		"op":    "less",
		"path":  "/z",
		"value": -0.5,
	},
	"less2": {
		"op":    "less",
		"path":  "",
		"value": 0,
	},

	"more1": {
		"op":    "more",
		"path":  "",
		"value": 1,
	},
	"more2": {
		"op":    "more",
		"path":  "/a",
		"value": -1,
	},

	"and1": {
		"op":   "and",
		"path": "/a",
		"apply": []interface{}{
			map[string]interface{}{"op": "test", "path": "/b", "value": 123},
		},
	},
	"and2": {
		"op":   "and",
		"path": "/",
		"apply": []interface{}{
			map[string]interface{}{"op": "less", "path": "", "value": 0},
			map[string]interface{}{"op": "more", "path": "", "value": 1},
			map[string]interface{}{"op": "in", "path": "/", "value": []interface{}{"asdf"}},
		},
	},
	"and3": {
		"op":   "and",
		"path": "/a/1/.",
		"apply": []interface{}{
			map[string]interface{}{"op": "test", "path": "", "value": nil},
			map[string]interface{}{"op": "test", "path": "/ha/hi", "value": map[string]interface{}{"foo": "bar"}},
			map[string]interface{}{"op": "test", "path": "/ha/1/2", "value": []interface{}{1, map[string]interface{}{"a": false}, "null"}},
		},
	},
	"and4": {
		"op":   "and",
		"path": "/a/1/.",
		"apply": []interface{}{
			map[string]interface{}{"op": "test", "path": "", "value": nil},
			map[string]interface{}{
				"op":   "and",
				"path": "/gg/bet",
				"apply": []interface{}{
					map[string]interface{}{"op": "test", "path": "", "value": nil},
					map[string]interface{}{"op": "test", "path": "/ha/hi", "value": map[string]interface{}{"foo": "bar"}},
				},
			},
			map[string]interface{}{"op": "test", "path": "/ha/hi", "value": map[string]interface{}{"foo": "bar"}},
		},
	},

	"not1": {
		"op":   "not",
		"path": "/",
		"apply": []interface{}{
			map[string]interface{}{"op": "less", "path": "", "value": 0},
			map[string]interface{}{"op": "more", "path": "", "value": 1},
			map[string]interface{}{"op": "in", "path": "/", "value": []interface{}{"asdf"}},
		},
	},
	"not2": {
		"op":   "not",
		"path": "/a/1/.",
		"apply": []interface{}{
			map[string]interface{}{"op": "test", "path": "", "value": nil},
			map[string]interface{}{"op": "test", "path": "/ha/hi", "value": map[string]interface{}{"foo": "bar"}},
			map[string]interface{}{"op": "test", "path": "/ha/1/2", "value": []interface{}{1, map[string]interface{}{"a": false}, "null"}},
		},
	},

	"or1": {
		"op":   "or",
		"path": "/",
		"apply": []interface{}{
			map[string]interface{}{"op": "less", "path": "", "value": 0},
			map[string]interface{}{"op": "more", "path": "", "value": 1},
			map[string]interface{}{"op": "in", "path": "/", "value": []interface{}{"asdf"}},
		},
	},
	"or2": {
		"op":   "or",
		"path": "/a/1/.",
		"apply": []interface{}{
			map[string]interface{}{"op": "test", "path": "", "value": nil},
			map[string]interface{}{"op": "test", "path": "/ha/hi", "value": map[string]interface{}{"foo": "bar"}},
			map[string]interface{}{"op": "test", "path": "/ha/1/2", "value": []interface{}{1, map[string]interface{}{"a": false}, "null"}},
		},
	},

	"str_ins1": {
		"op":   "str_ins",
		"path": "/ads",
		"pos":  0,
		"str":  "",
	},
	"str_ins2": {
		"op":   "str_ins",
		"path": "/a/b/lkasjdfoiasjdfoiasjdflaksjdflkasjfljasdflkjasdlfjkasdf",
		"pos":  823848493,
		"str":  "Component model",
	},

	"str_del1": {
		"op":   "str_del",
		"path": "",
		"pos":  0,
		"len":  0,
	},
	"str_del2": {
		"op":   "str_del",
		"path": "/asdfasdfasdfasdfasdfasdfasdfpalsdf902039joij2130j9e2093k2309k203f0sjdf0s9djf0skdfs0dfk092j0239j0mospdkf",
		"pos":  92303948,
		"len":  84487,
	},
	"str_del3": {
		"op":   "str_del",
		"path": "/asdf/reg/asdf/asdf/wer/sdaf234/asf/23/asdf2/asdf2",
		"pos":  92303948,
		"str":  "asdfasdfasdfasdflkasdjflakjsdf",
	},

	"flip1": {
		"op":   "flip",
		"path": "",
	},
	"flip2": {
		"op":   "flip",
		"path": "/asdf/df/dfa/dfasfd/",
	},

	"inc1": {
		"op":   "inc",
		"path": "/",
		"inc":  1,
	},
	"inc2": {
		"op":   "inc",
		"path": "/asdf/sd/d/f",
		"inc":  -123,
	},

	"split1": {
		"op":   "split",
		"path": "/i",
		"pos":  0,
	},
	"split2": {
		"op":   "split",
		"path": "/i/asdf/sdf/d",
		"pos":  123,
	},
	"split3": {
		"op":   "split",
		"path": "/i/asdf/sdf/d",
		"pos":  123,
		"props": map[string]interface{}{
			"foo": "bar",
			"a":   123,
		},
	},

	"merge1": {
		"op":   "merge",
		"path": "",
		"pos":  0,
	},
	"merge2": {
		"op":   "merge",
		"path": "/a/b/c",
		"pos":  123412341234,
		"props": map[string]interface{}{
			"foo": nil,
			"bar": 23,
			"baz": "asdf",
			"quz": true,
			"qux": []interface{}{1, "2", 3, true, false, nil},
		},
	},

	"extend1": {
		"op":    "extend",
		"path":  "/",
		"props": map[string]interface{}{},
	},
	"extend2": {
		"op":   "extend",
		"path": "/asdf/asdf/asdf",
		"props": map[string]interface{}{
			"foo": "bar",
		},
	},
	"extend3": {
		"op":   "extend",
		"path": "/asdf/asdf/asdf",
		"props": map[string]interface{}{
			"foo": "bar",
			"a":   nil,
			"b":   true,
		},
		"deleteNull": true,
	},
}

SampleOperations contains all the test operations from TypeScript version

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL