Repository: Geal/nom
Pull request #856 (2018-12-08 14:22:52)

Fix a link to the http11 sample code
Fix a broken link to http11 sample code in README.md.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/20526297/badge)](https://coveralls.io/builds/20526297)

Coverage remained the same at 87.587% when pulling **75990213a34cfcb0e00d23e5e42899bc4a0d5dd7 on oza:patch-1** into **49a20d4f2bca4b893108096905bb91ac47193b91 on Geal:master**.


Patch:
diff --git a/README.md b/README.md
index fd9d454..21c9bf2 100644
--- a/README.md
+++ b/README.md
@@ -101,7 +101,7 @@ formats such as JSON, nom can manage it, and provides you with useful tools:
 
 Example projects:
 
-- [HTTP proxy](https://github.com/sozu-proxy/sozu/blob/master/lib/src/parser/http11.rs)
+- [HTTP proxy](https://github.com/sozu-proxy/sozu/blob/master/lib/src/protocol/http/parser.rs)
 - [TOML parser](https://github.com/joelself/tomllib)
 
 ### Programming language parsers
@@ -237,6 +237,7 @@ Here is a list of known projects using nom:
   * [GLSL](https://github.com/phaazon/glsl)
   * [Lua](https://github.com/doomrobo/nom-lua53)
   * [SQL](https://github.com/ms705/nom-sql)
+  * [Elm](https://github.com/cout970/Elm-interpreter)
 - Interface definition formats:
   * [Thrift](https://github.com/thehydroimpulse/thrust)
 - Audio, video and image formats:


Test patch:
diff --git a/tests/json.rs b/tests/json.rs
index 2d5ca04..bb62de7 100644
--- a/tests/json.rs
+++ b/tests/json.rs
@@ -23,34 +23,34 @@ named!(float<f32>, flat_map!(recognize_float, parse_to!(f32)));
 named!(
   string<&str>,
   delimited!(
-    tag!("\""),
+    char!('"'),
     //map_res!(escaped!(call!(alphanumeric), '\\', is_a!("\"n\\")), str::from_utf8),
     map_res!(
       escaped!(take_while1!(is_alphanumeric), '\\', one_of!("\"n\\")),
       str::from_utf8
     ),
-    tag!("\"")
+    char!('"')
   )
 );
 
 named!(
   array<Vec<JsonValue>>,
   ws!(delimited!(
-    tag!("["),
-    separated_list!(tag!(","), value),
-    tag!("]")
+    char!('['),
+    separated_list!(char!(','), value),
+    char!(']')
   ))
 );
 
 named!(
   key_value<(&str, JsonValue)>,
-  ws!(separated_pair!(string, tag!(":"), value))
+  ws!(separated_pair!(string, char!(':'), value))
 );
 
 named!(
   hash<HashMap<String, JsonValue>>,
   ws!(map!(
-    delimited!(tag!("{"), separated_list!(tag!(","), key_value), tag!("}")),
+    delimited!(char!('{'), separated_list!(char!(','), key_value), char!('}')),
     |tuple_vec| {
       let mut h: HashMap<String, JsonValue> = HashMap::new();
       for (k, v) in tuple_vec {
@@ -72,25 +72,34 @@ named!(
 );
 
 #[test]
-fn hash_test() {
-  let test = &b"  { \"a\"\t: 42,
-  \"b\": \"x\"
-  }\0";
-
-  //FIXME: top level value must be an object?
-  println!("{:?}", value(&test[..]).unwrap());
-  //assert!(false);
+fn json_object() {
+  let input =
+    r#"{
+      "a": 42,
+      "b": "x"
+    }\0"#;
+
+  let mut expected_map = HashMap::new();
+  expected_map.insert(String::from("a"), JsonValue::Num(42f32));
+  expected_map.insert(String::from("b"), JsonValue::Str(String::from("x")));
+  let expected = JsonValue::Object(expected_map);
+
+  assert_eq!(expected, value(input.as_bytes()).unwrap().1);
 }
 
 #[test]
-fn parse_example_test() {
-  let test = &b"  { \"a\"\t: 42,
-  \"b\": [ \"x\", \"y\", 12 ] ,
-  \"c\": { \"hello\" : \"world\"
-  }
-  }\0";
-
-  //FIXME: top level value must be an object?
-  println!("{:?}", value(&test[..]).unwrap());
-  //assert!(false);
+fn json_array() {
+  let input =
+    r#"[
+      42,
+      "x"
+    ]\0"#;
+
+  let expected_vec = vec![
+    JsonValue::Num(42f32),
+    JsonValue::Str(String::from("x"))
+  ];
+  let expected = JsonValue::Array(expected_vec);
+
+  assert_eq!(expected, value(input.as_bytes()).unwrap().1);
 }