Skip to content

Commit c6176c6

Browse files
committed
add ability to test ./jsonpp
1 parent 7f6dbf2 commit c6176c6

8 files changed

+4235
-0
lines changed

data/expected_dup.json

Lines changed: 4108 additions & 0 deletions
Large diffs are not rendered by default.

data/expected_empty_blob.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

data/expected_long_malformed.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ERROR: Broken json on line 1, char 41: invalid character '"' after object key:value pair
2+
Context: ...afaefefadfas" "foo": "baaaaaaa...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{}
2+
ERROR: Broken json on line 2, char 1: invalid character '}' looking for beginning of value
3+
Context: }

data/expected_multiple.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"foo": "bar"
3+
}
4+
{
5+
"bar": "quux"
6+
}
7+
{
8+
"quux": "foo"
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

data/expected_tweet.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"place": null,
3+
"user": {
4+
"profile_link_color": "0084B4",
5+
"url": null,
6+
"following": null,
7+
"verified": false,
8+
"profile_sidebar_border_color": "C0DEED",
9+
"follow_request_sent": null,
10+
"show_all_inline_media": false,
11+
"geo_enabled": false,
12+
"profile_use_background_image": true,
13+
"profile_background_color": "C0DEED",
14+
"description": null,
15+
"is_translator": false,
16+
"profile_background_image_url": "http:\/\/a3.twimg.com\/a\/1298748610\/images\/themes\/theme1\/bg.png",
17+
"listed_count": 0,
18+
"statuses_count": 38,
19+
"created_at": "Sat Nov 13 05:26:45 +0000 2010",
20+
"protected": false,
21+
"profile_image_url": "http:\/\/a0.twimg.com\/sticky\/default_profile_images\/default_profile_3_normal.png",
22+
"time_zone": null,
23+
"favourites_count": 0,
24+
"profile_text_color": "333333",
25+
"location": null,
26+
"name": "Albert Lozoya",
27+
"contributors_enabled": false,
28+
"notifications": null,
29+
"profile_sidebar_fill_color": "DDEEF6",
30+
"screen_name": "Silentkill3r11",
31+
"id": 215173360,
32+
"id_str": "215173360",
33+
"lang": "en",
34+
"profile_background_tile": false,
35+
"utc_offset": null,
36+
"friends_count": 15,
37+
"followers_count": 1
38+
},
39+
"coordinates": null,
40+
"text": "@KAOS_CHEFS can't wait till tues so ready to fight in homefront",
41+
"in_reply_to_status_id": 47012944512421888,
42+
"truncated": false,
43+
"source": "\u003Ca href=\"http:\/\/twitter.com\/\" rel=\"nofollow\"\u003ETwitter for iPhone\u003C\/a\u003E",
44+
"favorited": false,
45+
"in_reply_to_screen_name": "KAOS_CHEFS",
46+
"in_reply_to_user_id": 19563357,
47+
"created_at": "Mon Mar 14 00:46:11 +0000 2011",
48+
"in_reply_to_status_id_str": "47012944512421888",
49+
"geo": null,
50+
"contributors": null,
51+
"retweeted": false,
52+
"id": 47096149311619072,
53+
"in_reply_to_user_id_str": "19563357",
54+
"id_str": "47096149311619072",
55+
"entities": {
56+
"urls": [],
57+
"hashtags": [],
58+
"user_mentions": [
59+
{
60+
"indices": [
61+
0,
62+
11
63+
],
64+
"name": "Jeremy Greiner",
65+
"screen_name": "KAOS_CHEFS",
66+
"id": 19563357,
67+
"id_str": "19563357"
68+
}
69+
]
70+
},
71+
"retweet_count": 0
72+
}

jsonpp_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"io/ioutil"
6+
"os/exec"
7+
"strings"
8+
"testing"
9+
)
10+
11+
func TestFiles(t *testing.T) {
12+
t.Logf("Reminder: This tests a jsonpp in the repo directory.")
13+
infos, err := ioutil.ReadDir("./data")
14+
if err != nil {
15+
t.Fatal(err)
16+
}
17+
for _, i := range infos {
18+
if i.Name() == "tweet.json" {
19+
continue
20+
}
21+
if strings.HasPrefix(i.Name(), "expected_") {
22+
continue
23+
}
24+
path := "./data/" + i.Name()
25+
expectedPath := "./data/expected_" + i.Name()
26+
cmd := exec.Command("./jsonpp", path)
27+
expected, err := ioutil.ReadFile(expectedPath)
28+
if err != nil {
29+
t.Error("unable to read %s: %s", expectedPath, err)
30+
}
31+
out, cerr := cmd.CombinedOutput()
32+
if !bytes.Equal(expected, out) {
33+
if cerr != nil {
34+
t.Logf("jsonpp cmd errored: %s", cerr)
35+
}
36+
t.Errorf("On %s, expected:\n%s\n=====\nGot:\n%s\n=====", i.Name(), string(expected), string(out))
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)