git.fiddlerwoaroof.com
Browse code

Run test cases from the specification

Fernando Borretti authored on 22/04/2015 22:30:15
Showing 24 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,12 @@
1
+[
2
+  {
3
+    "name": "Mark McGwire",
4
+    "hr": 65,
5
+    "avg": 0.278
6
+  },
7
+  {
8
+    "name": "Sammy Sosa",
9
+    "hr": 63,
10
+    "avg": 0.288
11
+  }
12
+]
0 13
new file mode 100644
... ...
@@ -0,0 +1,8 @@
1
+-
2
+  name: Mark McGwire
3
+  hr:   65
4
+  avg:  0.278
5
+-
6
+  name: Sammy Sosa
7
+  hr:   63
8
+  avg:  0.288
0 9
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+{ hr: 65, avg: 0.278, rbi: 147 }
0 2
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+hr:  65    # Home runs
2
+avg: 0.278 # Batting average
3
+rbi: 147   # Runs Batted In
0 4
new file mode 100644
... ...
@@ -0,0 +1,12 @@
1
+{
2
+  "american": [
3
+    "Boston Red Sox",
4
+    "Detroit Tigers",
5
+    "New York Yankees"
6
+  ],
7
+  "national": [
8
+    "New York Mets",
9
+    "Chicago Cubs",
10
+    "Atlanta Braves"
11
+  ]
12
+}
0 13
new file mode 100644
... ...
@@ -0,0 +1,8 @@
1
+american:
2
+  - Boston Red Sox
3
+  - Detroit Tigers
4
+  - New York Yankees
5
+national:
6
+  - New York Mets
7
+  - Chicago Cubs
8
+  - Atlanta Braves
0 9
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+[ "Mark McGwire", "Sammy Sosa", "Ken Griffey" ]
0 2
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+- Mark McGwire
2
+- Sammy Sosa
3
+- Ken Griffey
0 4
new file mode 100644
... ...
@@ -0,0 +1,17 @@
1
+[
2
+  [
3
+    "name",
4
+    "hr",
5
+    "avg"
6
+  ],
7
+  [
8
+    "Mark McGwire",
9
+    65,
10
+    0.278
11
+  ],
12
+  [
13
+    "Sammy Sosa",
14
+    63,
15
+    0.288
16
+  ]
17
+]
0 18
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+- [name        , hr, avg  ]
2
+- [Mark McGwire, 65, 0.278]
3
+- [Sammy Sosa  , 63, 0.288]
0 4
new file mode 100644
... ...
@@ -0,0 +1,41 @@
1
+{
2
+  "product": [
3
+    {
4
+      "sku": "BL394D",
5
+      "price": 450.0,
6
+      "description": "Basketball",
7
+      "quantity": 4
8
+    },
9
+    {
10
+      "sku": "BL4438H",
11
+      "price": 2392.0,
12
+      "description": "Super Hoop",
13
+      "quantity": 1
14
+    }
15
+  ],
16
+  "ship-to": {
17
+    "given": "Chris",
18
+    "family": "Dumars",
19
+    "address": {
20
+      "city": "Royal Oak",
21
+      "state": "MI",
22
+      "postal": 48046,
23
+      "lines": "458 Walkman Dr.\nSuite #292\n"
24
+    }
25
+  },
26
+  "tax": 251.41999999999999,
27
+  "comments": "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.",
28
+  "bill-to": {
29
+    "given": "Chris",
30
+    "family": "Dumars",
31
+    "address": {
32
+      "city": "Royal Oak",
33
+      "state": "MI",
34
+      "postal": 48046,
35
+      "lines": "458 Walkman Dr.\nSuite #292\n"
36
+    }
37
+  },
38
+  "invoice": 34843,
39
+  "date": "2001-01-23",
40
+  "total": 4443.5200000000004
41
+}
0 42
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+{
2
+  "data": "Mark McGwire's year was crippled by a knee injury.\n"
3
+}
0 4
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+data: >
2
+  Mark McGwire's
3
+  year was crippled
4
+  by a knee injury.
0 5
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+{
2
+  "name": "Mark McGwire",
3
+  "accomplishment": "Mark set a major league home run record in 1998.\n",
4
+  "stats": "65 Home Runs\n0.278 Batting Average\n"
5
+}
0 6
new file mode 100644
... ...
@@ -0,0 +1,7 @@
1
+name: Mark McGwire
2
+accomplishment: >
3
+  Mark set a major league
4
+  home run record in 1998.
5
+stats: |
6
+  65 Home Runs
7
+  0.278 Batting Average
0 8
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+{
2
+  "data": "Sammy Sosa completed another fine season with great stats.\n\n  63 Home Runs\n  0.288 Batting Average\n\nWhat a year!\n"
3
+}
0 4
new file mode 100644
... ...
@@ -0,0 +1,8 @@
1
+data: >
2
+ Sammy Sosa completed another
3
+ fine season with great stats.
4
+
5
+   63 Home Runs
6
+   0.288 Batting Average
7
+
8
+ What a year!
0 9
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+{
2
+  "plain": "This unquoted scalar spans many lines.",
3
+  "quoted": "So does this quoted scalar.\n"
4
+}
0 5
new file mode 100644
... ...
@@ -0,0 +1,6 @@
1
+plain:
2
+  This unquoted scalar
3
+  spans many lines.
4
+
5
+quoted: "So does this
6
+  quoted scalar.\n"
0 7
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+{
2
+  "data": "\\//||\\/||\n// ||  ||__\n"
3
+}
0 4
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+# ASCII Art
2
+data: |
3
+  \//||\/||
4
+  // ||  ||__
0 5
new file mode 100644
... ...
@@ -0,0 +1,8 @@
1
+{
2
+  "unicode": "Sosa did fine.☺",
3
+  "control": "\b1998\t1999\t2000\n",
4
+  "hex esc": "\r\n is \r\n",
5
+  "single": "\"Howdy!\" he cried.",
6
+  "quoted": " # Not a 'comment'.",
7
+  "tie-fighter": "|\\-*-/|"
8
+}
0 9
new file mode 100644
... ...
@@ -0,0 +1,7 @@
1
+unicode: "Sosa did fine.\u263A"
2
+control: "\b1998\t1999\t2000\n"
3
+hex esc: "\x0d\x0a is \r\n"
4
+
5
+single: '"Howdy!" he cried.'
6
+quoted: ' # Not a ''comment''.'
7
+tie-fighter: '|\-*-/|'
0 8
new file mode 100644
... ...
@@ -0,0 +1,27 @@
1
+(in-package :cl-user)
2
+(defpackage cl-yaml-test.spec
3
+  (:use :cl :fiveam)
4
+  (:export :spec))
5
+(in-package :cl-yaml-test.spec)
6
+
7
+(def-suite spec
8
+  :description "Test cases from the spec.")
9
+(in-suite spec)
10
+
11
+(defun parse-corresponding-file (yaml-file)
12
+  (let ((json-file (make-pathname :defaults yaml-file
13
+                                  :type "json")))
14
+    (yason:parse json-file)))
15
+
16
+(test spec-tests
17
+  (let ((directories (fad:list-directory
18
+                      (asdf:system-relative-pathname :cl-yaml-test
19
+                                                     #p"t/data/"))))
20
+    (loop for directory in directories do
21
+      (loop for file in (uiop:directory-files directory) do
22
+        (when (string= (pathname-type file) "yaml")
23
+          (format t "~%Spec: ~A" (pathname-name file))
24
+          (let ((data (yaml:parse file))
25
+                (json-data (parse-corresponding-file file)))
26
+            (is-true
27
+             (generic-comparability:equals data json-data))))))))