Repository: Geal/nom
Pull request #857 (2018-12-10 00:22:14)

Add gorrosion-gtp to known users
I'm slowly but steadily and ever-cursingly making progress writing a parser for [GTP](http://www.lysator.liu.se/~gunnar/gtp/). If this already meets the requirements for inclusion into the list, please merge this PR. Otherwise, I'll come back when it is more complete.

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

Coverage remained the same at 87.587% when pulling **dd4bb6e570f6541d712164235fa59732aec63b60 on fuerstenau:gorrosion-gtp** into **49a20d4f2bca4b893108096905bb91ac47193b91 on Geal:master**.


Patch:
diff --git a/README.md b/README.md
index fd9d454..4858f11 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:
@@ -260,6 +261,7 @@ Here is a list of known projects using nom:
   * [DER](https://github.com/rusticata/der-parser)
   * [TLS](https://github.com/rusticata/tls-parser)
   * [IPFIX / Netflow v10](https://github.com/dominotree/rs-ipfix)
+  * [GTP](https://github.com/fuerstenau/gorrosion-gtp)
 - Language specifications:
   * [BNF](https://github.com/snewt/bnf)
 


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);
 }