Skip to content

Commit 7053321

Browse files
author
James McLaughlin
committed
Merge pull request json-parser#50 from hannesgredler/master
make test.py compliant to python3, add .gitignore
2 parents c8f0af9 + 555f3ca commit 7053321

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Makefile
2+
config.log
3+
config.status
4+
json.o
5+
libjsonparser.a
6+
libjsonparser.so
7+
test_json

examples/test_json.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@
3636
/*
3737
* Test for json.c
3838
*
39-
* Compile with
39+
* Compile (static linking) with
4040
* gcc -o test_json -I.. test_json.c ../json.c -lm
4141
*
42+
* Compile (dynamic linking) with
43+
* gcc -o test_json -I.. test_json.c -lm -ljsonparser
44+
*
4245
* USAGE: ./test_json <json_file>
4346
*/
4447

@@ -99,7 +102,7 @@ static void process_value(json_value* value, int depth)
99102
process_array(value, depth+1);
100103
break;
101104
case json_integer:
102-
printf("int: %d\n", value->u.integer);
105+
printf("int: %10" PRId64 "\n", value->u.integer);
103106
break;
104107
case json_double:
105108
printf("double: %f\n", value->u.dbl);

tests/test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
try:
1717
jsonparser.decode(test)
1818
except jsonparser.JSONException as error:
19-
print 'valid/%d : Failed with error: %s' % (i, error)
19+
print ('valid/%d : Failed with error: %s' % (i, error))
2020
continue
2121

2222
py_decoded = json.loads(test)
@@ -25,24 +25,24 @@
2525
try:
2626
reencoded = jsonparser.decode(py_reencoded)
2727
except jsonparser.JSONException as error:
28-
print 'valid/%d : Failed on re-encoded version with error: %s' % (i, error)
28+
print ('valid/%d : Failed on re-encoded version with error: %s' % (i, error))
2929
continue
3030

3131
if reencoded != py_decoded:
32-
print 'valid/%d : %s:\n\n%s\n\nbecame\n\n%s\n' % (i, failed, test, reencoded)
32+
print ('valid/%d : %s:\n\n%s\n\nbecame\n\n%s\n' % (i, failed, test, reencoded))
3333
else:
34-
print 'valid/%d : %s' % (i, passed)
34+
print ('valid/%d : %s' % (i, passed))
3535

3636
for i, test in enumerate(
3737
map(lambda file: open(file).read(), sorted(glob.glob('invalid*.json')))):
3838

3939
try:
4040
jsonparser.decode(test)
4141
except jsonparser.JSONException as error:
42-
print 'invalid/%d : %s: %s' % (i, passed, error)
42+
print ('invalid/%d : %s: %s' % (i, passed, error))
4343
continue
4444

45-
print 'invalid/%d : %s (parsing succeeded and shouldn\'t have)' % (i, failed)
45+
print ('invalid/%d : %s (parsing succeeded and shouldn\'t have)' % (i, failed))
4646

4747

4848
# Extension tests
@@ -52,9 +52,9 @@
5252

5353
try:
5454
decoded = jsonparser.decode(test)
55-
print 'ext-valid/%d : %s: %s' % (i, passed, json.dumps(decoded))
55+
print ('ext-valid/%d : %s: %s' % (i, passed, json.dumps(decoded)))
5656
except jsonparser.JSONException as error:
57-
print 'ext-valid/%d : Failed with error: %s' % (i, error)
57+
print ('ext-valid/%d : Failed with error: %s' % (i, error))
5858
continue
5959

6060
for i, test in enumerate(
@@ -63,8 +63,8 @@
6363
try:
6464
jsonparser.decode(test)
6565
except jsonparser.JSONException as error:
66-
print 'ext-invalid/%d : %s: %s' % (i, passed, error)
66+
print ('ext-invalid/%d : %s: %s' % (i, passed, error))
6767
continue
6868

69-
print 'ext-invalid/%d : %s (parsing succeeded and shouldn\'t have)' % (i, failed)
69+
print ('ext-invalid/%d : %s (parsing succeeded and shouldn\'t have)' % (i, failed))
7070

0 commit comments

Comments
 (0)