|
1 | | -import { isJsonCompatibleArray, isJsonCompatibleDictionary, isJsonCompatibleValue } from "./json"; |
| 1 | +import { isJsonArray, isJsonObject, isJsonValue } from "./json"; |
2 | 2 |
|
3 | 3 | describe("json", () => { |
4 | 4 | function sum(a: number, b: number): number { |
5 | 5 | return a + b; |
6 | 6 | } |
7 | 7 |
|
8 | | - describe("isJsonCompatibleValue", () => { |
| 8 | + describe("isJsonValue", () => { |
9 | 9 | it("returns true for primitive types", () => { |
10 | | - expect(isJsonCompatibleValue(null)).toEqual(true); |
11 | | - expect(isJsonCompatibleValue(0)).toEqual(true); |
12 | | - expect(isJsonCompatibleValue(1)).toEqual(true); |
13 | | - expect(isJsonCompatibleValue("abc")).toEqual(true); |
14 | | - expect(isJsonCompatibleValue(true)).toEqual(true); |
15 | | - expect(isJsonCompatibleValue(false)).toEqual(true); |
| 10 | + expect(isJsonValue(null)).toEqual(true); |
| 11 | + expect(isJsonValue(0)).toEqual(true); |
| 12 | + expect(isJsonValue(1)).toEqual(true); |
| 13 | + expect(isJsonValue("abc")).toEqual(true); |
| 14 | + expect(isJsonValue(true)).toEqual(true); |
| 15 | + expect(isJsonValue(false)).toEqual(true); |
16 | 16 | }); |
17 | 17 |
|
18 | 18 | it("returns true for arrays", () => { |
19 | | - expect(isJsonCompatibleValue([1, 2, 3])).toEqual(true); |
20 | | - expect(isJsonCompatibleValue([1, "2", true, null])).toEqual(true); |
21 | | - expect(isJsonCompatibleValue([1, "2", true, null, [1, "2", true, null]])).toEqual(true); |
22 | | - expect(isJsonCompatibleValue([{ a: 123 }])).toEqual(true); |
| 19 | + expect(isJsonValue([1, 2, 3])).toEqual(true); |
| 20 | + expect(isJsonValue([1, "2", true, null])).toEqual(true); |
| 21 | + expect(isJsonValue([1, "2", true, null, [1, "2", true, null]])).toEqual(true); |
| 22 | + expect(isJsonValue([{ a: 123 }])).toEqual(true); |
23 | 23 | }); |
24 | 24 |
|
25 | 25 | it("returns true for simple dicts", () => { |
26 | | - expect(isJsonCompatibleValue({ a: 123 })).toEqual(true); |
27 | | - expect(isJsonCompatibleValue({ a: "abc" })).toEqual(true); |
28 | | - expect(isJsonCompatibleValue({ a: true })).toEqual(true); |
29 | | - expect(isJsonCompatibleValue({ a: null })).toEqual(true); |
| 26 | + expect(isJsonValue({ a: 123 })).toEqual(true); |
| 27 | + expect(isJsonValue({ a: "abc" })).toEqual(true); |
| 28 | + expect(isJsonValue({ a: true })).toEqual(true); |
| 29 | + expect(isJsonValue({ a: null })).toEqual(true); |
30 | 30 | }); |
31 | 31 |
|
32 | 32 | it("returns true for dict with array", () => { |
33 | | - expect(isJsonCompatibleValue({ a: [1, 2, 3] })).toEqual(true); |
34 | | - expect(isJsonCompatibleValue({ a: [1, "2", true, null] })).toEqual(true); |
| 33 | + expect(isJsonValue({ a: [1, 2, 3] })).toEqual(true); |
| 34 | + expect(isJsonValue({ a: [1, "2", true, null] })).toEqual(true); |
35 | 35 | }); |
36 | 36 |
|
37 | 37 | it("returns true for nested dicts", () => { |
38 | | - expect(isJsonCompatibleValue({ a: { b: 123 } })).toEqual(true); |
| 38 | + expect(isJsonValue({ a: { b: 123 } })).toEqual(true); |
39 | 39 | }); |
40 | 40 |
|
41 | 41 | it("returns false for functions", () => { |
42 | | - expect(isJsonCompatibleValue(sum)).toEqual(false); |
| 42 | + expect(isJsonValue(sum)).toEqual(false); |
43 | 43 | }); |
44 | 44 |
|
45 | 45 | it("returns true for empty dicts", () => { |
46 | | - expect(isJsonCompatibleValue({})).toEqual(true); |
| 46 | + expect(isJsonValue({})).toEqual(true); |
47 | 47 | }); |
48 | 48 | }); |
49 | 49 |
|
50 | | - describe("isJsonCompatibleArray", () => { |
| 50 | + describe("isJsonArray", () => { |
51 | 51 | it("returns false for primitive types", () => { |
52 | | - expect(isJsonCompatibleArray(null)).toEqual(false); |
53 | | - expect(isJsonCompatibleArray(undefined)).toEqual(false); |
54 | | - expect(isJsonCompatibleArray(0)).toEqual(false); |
55 | | - expect(isJsonCompatibleArray(1)).toEqual(false); |
56 | | - expect(isJsonCompatibleArray("abc")).toEqual(false); |
57 | | - expect(isJsonCompatibleArray(true)).toEqual(false); |
58 | | - expect(isJsonCompatibleArray(false)).toEqual(false); |
| 52 | + expect(isJsonArray(null)).toEqual(false); |
| 53 | + expect(isJsonArray(undefined)).toEqual(false); |
| 54 | + expect(isJsonArray(0)).toEqual(false); |
| 55 | + expect(isJsonArray(1)).toEqual(false); |
| 56 | + expect(isJsonArray("abc")).toEqual(false); |
| 57 | + expect(isJsonArray(true)).toEqual(false); |
| 58 | + expect(isJsonArray(false)).toEqual(false); |
59 | 59 | }); |
60 | 60 |
|
61 | 61 | it("returns true for arrays", () => { |
62 | | - expect(isJsonCompatibleArray([1, 2, 3])).toEqual(true); |
63 | | - expect(isJsonCompatibleArray([1, "2", true, null])).toEqual(true); |
64 | | - expect(isJsonCompatibleArray([1, "2", true, null, [1, "2", true, null]])).toEqual(true); |
65 | | - expect(isJsonCompatibleArray([{ a: 123 }])).toEqual(true); |
| 62 | + expect(isJsonArray([1, 2, 3])).toEqual(true); |
| 63 | + expect(isJsonArray([1, "2", true, null])).toEqual(true); |
| 64 | + expect(isJsonArray([1, "2", true, null, [1, "2", true, null]])).toEqual(true); |
| 65 | + expect(isJsonArray([{ a: 123 }])).toEqual(true); |
66 | 66 | }); |
67 | 67 |
|
68 | 68 | it("returns false for dicts", () => { |
69 | | - expect(isJsonCompatibleArray({ a: 123 })).toEqual(false); |
70 | | - expect(isJsonCompatibleArray({ a: "abc" })).toEqual(false); |
71 | | - expect(isJsonCompatibleArray({ a: true })).toEqual(false); |
72 | | - expect(isJsonCompatibleArray({ a: null })).toEqual(false); |
| 69 | + expect(isJsonArray({ a: 123 })).toEqual(false); |
| 70 | + expect(isJsonArray({ a: "abc" })).toEqual(false); |
| 71 | + expect(isJsonArray({ a: true })).toEqual(false); |
| 72 | + expect(isJsonArray({ a: null })).toEqual(false); |
73 | 73 | }); |
74 | 74 |
|
75 | 75 | it("returns false for functions", () => { |
76 | | - expect(isJsonCompatibleArray(sum)).toEqual(false); |
| 76 | + expect(isJsonArray(sum)).toEqual(false); |
77 | 77 | }); |
78 | 78 | }); |
79 | 79 |
|
80 | | - describe("isJsonCompatibleDictionary", () => { |
| 80 | + describe("isJsonObject", () => { |
81 | 81 | it("returns false for primitive types", () => { |
82 | | - expect(isJsonCompatibleDictionary(null)).toEqual(false); |
83 | | - expect(isJsonCompatibleDictionary(undefined)).toEqual(false); |
84 | | - expect(isJsonCompatibleDictionary(0)).toEqual(false); |
85 | | - expect(isJsonCompatibleDictionary(1)).toEqual(false); |
86 | | - expect(isJsonCompatibleDictionary("abc")).toEqual(false); |
87 | | - expect(isJsonCompatibleDictionary(true)).toEqual(false); |
88 | | - expect(isJsonCompatibleDictionary(false)).toEqual(false); |
| 82 | + expect(isJsonObject(null)).toEqual(false); |
| 83 | + expect(isJsonObject(undefined)).toEqual(false); |
| 84 | + expect(isJsonObject(0)).toEqual(false); |
| 85 | + expect(isJsonObject(1)).toEqual(false); |
| 86 | + expect(isJsonObject("abc")).toEqual(false); |
| 87 | + expect(isJsonObject(true)).toEqual(false); |
| 88 | + expect(isJsonObject(false)).toEqual(false); |
89 | 89 | }); |
90 | 90 |
|
91 | 91 | it("returns false for other objects", () => { |
92 | | - expect(isJsonCompatibleDictionary(new Uint8Array([0x00]))).toEqual(false); |
93 | | - expect(isJsonCompatibleDictionary(/123/)).toEqual(false); |
94 | | - expect(isJsonCompatibleDictionary(new Date())).toEqual(false); |
| 92 | + expect(isJsonObject(new Uint8Array([0x00]))).toEqual(false); |
| 93 | + expect(isJsonObject(/123/)).toEqual(false); |
| 94 | + expect(isJsonObject(new Date())).toEqual(false); |
95 | 95 | }); |
96 | 96 |
|
97 | 97 | it("returns false for arrays", () => { |
98 | | - expect(isJsonCompatibleDictionary([1, 2, 3])).toEqual(false); |
| 98 | + expect(isJsonObject([1, 2, 3])).toEqual(false); |
99 | 99 | }); |
100 | 100 |
|
101 | 101 | it("returns false for functions", () => { |
102 | | - expect(isJsonCompatibleDictionary(sum)).toEqual(false); |
| 102 | + expect(isJsonObject(sum)).toEqual(false); |
103 | 103 | }); |
104 | 104 |
|
105 | 105 | it("returns true for empty dicts", () => { |
106 | | - expect(isJsonCompatibleDictionary({})).toEqual(true); |
| 106 | + expect(isJsonObject({})).toEqual(true); |
107 | 107 | }); |
108 | 108 |
|
109 | 109 | it("returns true for simple dicts", () => { |
110 | | - expect(isJsonCompatibleDictionary({ a: 123 })).toEqual(true); |
111 | | - expect(isJsonCompatibleDictionary({ a: "abc" })).toEqual(true); |
112 | | - expect(isJsonCompatibleDictionary({ a: true })).toEqual(true); |
113 | | - expect(isJsonCompatibleDictionary({ a: null })).toEqual(true); |
| 110 | + expect(isJsonObject({ a: 123 })).toEqual(true); |
| 111 | + expect(isJsonObject({ a: "abc" })).toEqual(true); |
| 112 | + expect(isJsonObject({ a: true })).toEqual(true); |
| 113 | + expect(isJsonObject({ a: null })).toEqual(true); |
114 | 114 | }); |
115 | 115 |
|
116 | 116 | it("returns true for dict with array", () => { |
117 | | - expect(isJsonCompatibleDictionary({ a: [1, 2, 3] })).toEqual(true); |
118 | | - expect(isJsonCompatibleDictionary({ a: [1, "2", true, null] })).toEqual(true); |
| 117 | + expect(isJsonObject({ a: [1, 2, 3] })).toEqual(true); |
| 118 | + expect(isJsonObject({ a: [1, "2", true, null] })).toEqual(true); |
119 | 119 | }); |
120 | 120 |
|
121 | 121 | it("returns true for nested dicts", () => { |
122 | | - expect(isJsonCompatibleDictionary({ a: { b: 123 } })).toEqual(true); |
| 122 | + expect(isJsonObject({ a: { b: 123 } })).toEqual(true); |
123 | 123 | }); |
124 | 124 | }); |
125 | 125 | }); |
0 commit comments