Add test/data/cbor-rfc-7049-examples.*
diff --git a/script/extract-cbor-rfc-7049-examples.go b/script/extract-cbor-rfc-7049-examples.go
index 3ef9de9..be10da2 100644
--- a/script/extract-cbor-rfc-7049-examples.go
+++ b/script/extract-cbor-rfc-7049-examples.go
@@ -17,8 +17,10 @@
package main
// extract-cbor-rfc-7049-examples.go extracts the examples (Appendix A) from
-// RFC 7049 "Concise Binary Object Representation (CBOR)". Each example is
-// written to a separate file under a "cbor-rfc-7049-examples" directory.
+// RFC 7049 "Concise Binary Object Representation (CBOR)". If the -concat flag
+// is passed, a single CBOR array containing all of the examples are written to
+// stdout. Otherwise, each example is written to a separate file under a
+// "cbor-rfc-7049-examples" directory.
//
// Usage:
// go run extract-cbor-rfc-7049-examples.go < rfc7049-errata-corrected.txt
@@ -31,11 +33,14 @@
import (
"bytes"
+ "flag"
"fmt"
"io/ioutil"
"os"
)
+var concat = flag.Bool("concat", false, "output one monolithic CBOR file")
+
func main() {
if err := main1(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
@@ -48,7 +53,10 @@
if err != nil {
return err
}
- if err := os.Mkdir("cbor-rfc-7049-examples", 0755); err != nil {
+ if *concat {
+ // Start of CBOR indefinite-length array.
+ os.Stdout.Write([]byte("\x9F"))
+ } else if err := os.Mkdir("cbor-rfc-7049-examples", 0755); err != nil {
return err
}
for remaining := []byte(nil); len(src) > 0; src = remaining {
@@ -78,7 +86,14 @@
contents = append(contents, (unhex(src[0])<<4)|unhex(src[1]))
}
}
- return emit()
+ if err := emit(); err != nil {
+ return err
+ }
+ if *concat {
+ // End of CBOR indefinite-length array.
+ os.Stdout.Write([]byte("\xFF"))
+ }
+ return nil
}
var (
@@ -90,6 +105,11 @@
if len(contents) == 0 {
return nil
}
+ if *concat {
+ os.Stdout.Write(contents)
+ contents = nil
+ return nil
+ }
filename := fmt.Sprintf("cbor-rfc-7049-examples/%02d.cbor", fileNumber)
fileNumber++
err := ioutil.WriteFile(filename, contents, 0644)
diff --git a/test/c/std/cbor.c b/test/c/std/cbor.c
index e903a63..18a73ea 100644
--- a/test/c/std/cbor.c
+++ b/test/c/std/cbor.c
@@ -67,13 +67,27 @@
// No mimic library.
#endif
+// ---------------- Golden Tests
+
+golden_test g_cbor_cbor_rfc_7049_examples_gt = {
+ .want_filename = "test/data/cbor-rfc-7049-examples.tokens",
+ .src_filename = "test/data/cbor-rfc-7049-examples.cbor",
+};
+
// ---------------- CBOR Tests
const char* //
test_wuffs_cbor_decode_interface() {
CHECK_FOCUS(__func__);
- // TODO.
+ wuffs_cbor__decoder dec;
+ CHECK_STATUS("initialize",
+ wuffs_cbor__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
+ CHECK_STRING(do_test__wuffs_base__token_decoder(
+ wuffs_cbor__decoder__upcast_as__wuffs_base__token_decoder(&dec),
+ &g_cbor_cbor_rfc_7049_examples_gt));
return NULL;
}
diff --git a/test/data/README.md b/test/data/README.md
index 94dc070..ba67800 100644
--- a/test/data/README.md
+++ b/test/data/README.md
@@ -33,6 +33,9 @@
`bricks-*` are various encodings of an original photo by Nigel Tao
<nigeltao@golang.org>.
+`cbor-rfc-7049-examples.cbor` is the concatenated examples from RFC 7049. The
+`cbor-rfc-7049-examples.*.json` files were then generated by `example/jsonptr`.
+
`crude-flag.*` is an original animation by Nigel Tao
<nigeltao@golang.org>. See the `lib/nie` documentation.
diff --git a/test/data/cbor-rfc-7049-examples.cbor b/test/data/cbor-rfc-7049-examples.cbor
new file mode 100644
index 0000000..51a2fc9
--- /dev/null
+++ b/test/data/cbor-rfc-7049-examples.cbor
Binary files differ
diff --git a/test/data/cbor-rfc-7049-examples.sans-comments.json b/test/data/cbor-rfc-7049-examples.sans-comments.json
new file mode 100644
index 0000000..419f2cb
--- /dev/null
+++ b/test/data/cbor-rfc-7049-examples.sans-comments.json
@@ -0,0 +1,224 @@
+[
+ 0,
+ 1,
+ 10,
+ 23,
+ 24,
+ 25,
+ 100,
+ 1000,
+ 1000000,
+ 1000000000000,
+ 18446744073709551615,
+ "AQAAAAAAAAAA",
+ -18446744073709551616,
+ "AQAAAAAAAAAA",
+ -1,
+ -10,
+ -100,
+ -1000,
+ 0,
+ -0,
+ 1,
+ 1.1,
+ 1.5,
+ 65504,
+ 100000,
+ 3.4028234663852886e+38,
+ 1e+300,
+ 5.960464477539063e-08,
+ 6.103515625e-05,
+ -4,
+ -4.1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ false,
+ true,
+ null,
+ null,
+ null,
+ null,
+ null,
+ "2013-03-21T20:04:00Z",
+ 1363896240,
+ 1.3638962405e+09,
+ "AQIDBA",
+ "ZElFVEY",
+ "http://www.example.com",
+ "",
+ "AQIDBA",
+ "",
+ "a",
+ "IETF",
+ "\"\\",
+ "ü",
+ "水",
+ "𐅑",
+ [],
+ [
+ 1,
+ 2,
+ 3
+ ],
+ [
+ 1,
+ [
+ 2,
+ 3
+ ],
+ [
+ 4,
+ 5
+ ]
+ ],
+ [
+ 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
+ ],
+ {},
+ {
+ "1": 2,
+ "3": 4
+ },
+ {
+ "a": 1,
+ "b": [
+ 2,
+ 3
+ ]
+ },
+ [
+ "a",
+ {
+ "b": "c"
+ }
+ ],
+ {
+ "a": "A",
+ "b": "B",
+ "c": "C",
+ "d": "D",
+ "e": "E"
+ },
+ "AQIDBAU",
+ "streaming",
+ [],
+ [
+ 1,
+ [
+ 2,
+ 3
+ ],
+ [
+ 4,
+ 5
+ ]
+ ],
+ [
+ 1,
+ [
+ 2,
+ 3
+ ],
+ [
+ 4,
+ 5
+ ]
+ ],
+ [
+ 1,
+ [
+ 2,
+ 3
+ ],
+ [
+ 4,
+ 5
+ ]
+ ],
+ [
+ 1,
+ [
+ 2,
+ 3
+ ],
+ [
+ 4,
+ 5
+ ]
+ ],
+ [
+ 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
+ ],
+ {
+ "a": 1,
+ "b": [
+ 2,
+ 3
+ ]
+ },
+ [
+ "a",
+ {
+ "b": "c"
+ }
+ ],
+ {
+ "Fun": true,
+ "Amt": -2
+ }
+]
diff --git a/test/data/cbor-rfc-7049-examples.tokens b/test/data/cbor-rfc-7049-examples.tokens
new file mode 100644
index 0000000..0a3d379
--- /dev/null
+++ b/test/data/cbor-rfc-7049-examples.tokens
Binary files differ
diff --git a/test/data/cbor-rfc-7049-examples.with-comments.json b/test/data/cbor-rfc-7049-examples.with-comments.json
new file mode 100644
index 0000000..b35a473
--- /dev/null
+++ b/test/data/cbor-rfc-7049-examples.with-comments.json
@@ -0,0 +1,224 @@
+[
+ 0,
+ 1,
+ 10,
+ 23,
+ 24,
+ 25,
+ 100,
+ 1000,
+ 1000000,
+ 1000000000000,
+ 18446744073709551615,
+ /*cbor:tag2*//*cbor:base64url*/"AQAAAAAAAAAA",
+ -18446744073709551616,
+ /*cbor:tag3*//*cbor:base64url*/"AQAAAAAAAAAA",
+ -1,
+ -10,
+ -100,
+ -1000,
+ 0,
+ -0,
+ 1,
+ 1.1,
+ 1.5,
+ 65504,
+ 100000,
+ 3.4028234663852886e+38,
+ 1e+300,
+ 5.960464477539063e-08,
+ 6.103515625e-05,
+ -4,
+ -4.1,
+ /*cbor:Inf*/null,
+ /*cbor:NaN*/null,
+ /*cbor:-Inf*/null,
+ /*cbor:Inf*/null,
+ /*cbor:NaN*/null,
+ /*cbor:-Inf*/null,
+ /*cbor:Inf*/null,
+ /*cbor:NaN*/null,
+ /*cbor:-Inf*/null,
+ false,
+ true,
+ null,
+ /*cbor:undefined*/null,
+ /*cbor:simple16*/null,
+ /*cbor:simple24*/null,
+ /*cbor:simple255*/null,
+ /*cbor:tag0*/"2013-03-21T20:04:00Z",
+ /*cbor:tag1*/1363896240,
+ /*cbor:tag1*/1.3638962405e+09,
+ /*cbor:tag23*//*cbor:base64url*/"AQIDBA",
+ /*cbor:tag24*//*cbor:base64url*/"ZElFVEY",
+ /*cbor:tag32*/"http://www.example.com",
+ /*cbor:base64url*/"",
+ /*cbor:base64url*/"AQIDBA",
+ "",
+ "a",
+ "IETF",
+ "\"\\",
+ "ü",
+ "水",
+ "𐅑",
+ [],
+ [
+ 1,
+ 2,
+ 3
+ ],
+ [
+ 1,
+ [
+ 2,
+ 3
+ ],
+ [
+ 4,
+ 5
+ ]
+ ],
+ [
+ 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
+ ],
+ {},
+ {
+ "1": 2,
+ "3": 4
+ },
+ {
+ "a": 1,
+ "b": [
+ 2,
+ 3
+ ]
+ },
+ [
+ "a",
+ {
+ "b": "c"
+ }
+ ],
+ {
+ "a": "A",
+ "b": "B",
+ "c": "C",
+ "d": "D",
+ "e": "E"
+ },
+ /*cbor:base64url*/"AQIDBAU",
+ "streaming",
+ [],
+ [
+ 1,
+ [
+ 2,
+ 3
+ ],
+ [
+ 4,
+ 5
+ ]
+ ],
+ [
+ 1,
+ [
+ 2,
+ 3
+ ],
+ [
+ 4,
+ 5
+ ]
+ ],
+ [
+ 1,
+ [
+ 2,
+ 3
+ ],
+ [
+ 4,
+ 5
+ ]
+ ],
+ [
+ 1,
+ [
+ 2,
+ 3
+ ],
+ [
+ 4,
+ 5
+ ]
+ ],
+ [
+ 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
+ ],
+ {
+ "a": 1,
+ "b": [
+ 2,
+ 3
+ ]
+ },
+ [
+ "a",
+ {
+ "b": "c"
+ }
+ ],
+ {
+ "Fun": true,
+ "Amt": -2
+ }
+]