summaryrefslogtreecommitdiff
path: root/test/run.scm
blob: a2a515b52f41766a936a8fb9d2fd91c5ade1a830 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(test-assert "json-object should meet json-object?"
  (json-object? (json-object)))

(test-assert "json-object should meet json-object?"
  (json-object? (json-object '(name . "alice")
			     '(age . 26))))

(test-assert "json-object should not meet json-list?"
  (not (json-list? (json-object '(x . 5)))))

(test-assert "json-list should not meet json-object?"
  (not (json-object? (json-list 1 2 3))))

(test-assert "json-list should meet json-list?"
  (json-list? (json-list)))

(test-assert "json-list should meet json-list?"
  (json-list? (json-list "a" 1 #t)))

(test-assert "json-null should meet json-null?"
  (json-null? json-null))

(test-assert "numbers should meet json-value?"
  (json-value? 5))

(test-assert "strings should meet json-value?"
  (json-value? "hello"))

(test-assert "booleans should meet json-value?"
  (json-value? #t))

(test-assert "json-objects should meet json-value?"
  (json-value? (json-object '(x . 5))))

(test-assert "json-lists should meet json-value?"
  (json-value? (json-list 1 2 3)))

(test-assert "json-object-contains-key? should return true when the object contains the key"
  (json-object-contains-key? (json-object '(x . 5)) 'x))

(test-assert "json-object-contains-key? should return false when the object does not contain the key"
  (not (json-object-contains-key? (json-object '(x . 5)) 'y)))

(test-assert "the null string should meet json-null? when parsed"
  (json-null? (string->json "null")))

(test-equal "numbers should parse to their scheme values"
      5 (string->json "5"))

(test-equal "true should parse to the boolean true"
      #t (string->json "true"))

(test-equal "false should parse to the boolean false"
      #f (string->json "false"))

(test-equal "string->json should properly parse string values"
      "hello" (string->json "\"hello\""))

(test-assert "string->json should return an object with the correct keys"
  (json-object-contains-key? (string->json "{\"x\": 5}") 'x))

(test-assert "string->json should return an object without the incorrect keys"
  (not (json-object-contains-key? (string->json "{\"x\": 5}") 'y)))

(test-assert "json-object-contains-key? should be met when the associated value is false"
  (json-object-contains-key? (json-object '(x . #f)) 'x))

(test-assert "json-object-contains-key? should be met when the associated value is an empty json-list"
  (json-object-contains-key? (json-object `(x . ,(json-list))) 'x))

(test-assert "json-object-contains-key? should be met when the associated value is an empty json-object"
  (json-object-contains-key? (json-object `(x . ,(json-object))) 'x))

(test-assert "json-object-contains-key? should be met when the associated value is json-null"
  (json-object-contains-key? (json-object `(x . ,json-null)) 'x))

(test-equal "json-ref should get a value associated with a key in an object"
  5 (json-ref (json-object '(x . 5)) 'x))

(test-equal "json-ref should get the value at an index of a list"
  5 (json-ref (json-object '(x . 5) '(y . #t)) 'x))

(test-equal "json-ref should get the value at an index of a list"
  2 (json-ref (json-list 1 2 3) 1))

(test-equal "json-ref should recursively get a value in a list in an object"
  json-null (json-ref (json-object `(x . ,(json-list #t json-null #f))) 'x 1))

(test-equal "json-ref should recursively get a value in an object in a list"
  5 (json-ref (json-list (json-object) (json-object '(a . 4) '(b . 5) '(c . 6)) #t) 1 'b))

;; (json (object))				; => {}

;; (json (list))				; => []

;; (json null)				; => null