Skip to content

Commit

Permalink
Fix bug in string-only load case. Improve test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Oct 8, 2020
1 parent 5137d68 commit 3b9ed60
Show file tree
Hide file tree
Showing 28 changed files with 175 additions and 125 deletions.
15 changes: 1 addition & 14 deletions nestedtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,6 @@ def indentation_error(line, depth):
report('invalid indentation.', line, colno=depth)


# is_quoted {{{2
def is_quoted(s):
return s[:1] in ['"', "'"] and s[:1] == s[-1:]


# dequote {{{2
def dequote(s):
s = s.strip()
if is_quoted(s):
return s[1:-1]
return s


# Lines class {{{2
class Lines:
# constructor {{{3
Expand Down Expand Up @@ -467,7 +454,7 @@ def read_all(lines, top, source, on_dup):

if top == 'str':
if next_is == "string item":
return read_list(lines, 0, on_dup)
return read_string(lines, 0)
elif next_is:
report('content must start with greater-than sign (>).', lines.get_next())
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/dict_06/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 1,
"colno": 0,
"message": "invalid indentation"
"message": "invalid indentation."
}
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/dict_07/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 2,
"colno": 0,
"message": "invalid indentation"
"message": "invalid indentation."
}
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/dict_08/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 3,
"colno": 4,
"message": "invalid character in indentation: '\\t'"
"message": "invalid character in indentation: '\\t'."
}
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/dict_09/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 2,
"colno": 0,
"message": "expected dictionary item"
"message": "expected dictionary item."
}
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/dict_10/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 3,
"colno": 2,
"message": "invalid indentation"
"message": "invalid indentation."
}
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/dict_11/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 3,
"colno": 0,
"message": "invalid indentation"
"message": "invalid indentation."
}
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/dict_12/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 3,
"colno": 0,
"message": "expected dictionary item"
"message": "expected dictionary item."
}
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/dict_13/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 2,
"colno": null,
"message": "unrecognized line"
"message": "unrecognized line."
}
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/dict_14/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 2,
"colno": 0,
"message": "duplicate key: key"
"message": "duplicate key: key."
}
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/dict_15/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 2,
"colno": 4,
"message": "invalid character in indentation: '\\t'"
"message": "invalid character in indentation: '\\t'."
}
15 changes: 7 additions & 8 deletions tests/official_tests/test_cases/list_2/load_in.nt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
key:
- A
- B
- C
-
- D1
- D2
- E
- A
- B
- C
-
- D1
- D2
- E
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/list_2/load_out.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"key": ["A", "B", "C", ["D1", "D2"], "E"]}
["A", "B", "C", ["D1", "D2"], "E"]
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/list_4/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 3,
"colno": 2,
"message": "expected list item"
"message": "expected list item."
}
4 changes: 2 additions & 2 deletions tests/official_tests/test_cases/list_5/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 5,
"lineno": 2,
"colno": 0,
"message": "invalid indentation"
"message": "invalid indentation."
}
5 changes: 2 additions & 3 deletions tests/official_tests/test_cases/list_5/load_in.nt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
ingredients:

- green chilies
- green chilies

- red chilies
- red chilies

6 changes: 3 additions & 3 deletions tests/official_tests/test_cases/list_6/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 3,
"colno": 4,
"message": "invalid indentation"
"lineno": 2,
"colno": 0,
"message": "invalid indentation."
}
5 changes: 2 additions & 3 deletions tests/official_tests/test_cases/list_6/load_in.nt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ingredients:
- green chilies
- red chilies
- green chilies
- red chilies

23 changes: 11 additions & 12 deletions tests/official_tests/test_cases/list_7/dump_out.nt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
:
- :
- ~!@#$%^&*()_+-1234567890{}[]|\:;<>?,./
- - value 3
- ' : value 4:'
- > value 5
- #value 6
- key 7' : : value 7
- " value 8 "
- ' value 9 '
- value '" 10
- And Fred said 'yabba dabba doo!' to Barney.
- :
- ~!@#$%^&*()_+-1234567890{}[]|\:;<>?,./
- - value 3
- ' : value 4:'
- > value 5
- #value 6
- key 7' : : value 7
- " value 8 "
- ' value 9 '
- value '" 10
- And Fred said 'yabba dabba doo!' to Barney.
25 changes: 12 additions & 13 deletions tests/official_tests/test_cases/list_7/load_in.nt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
:
- :
- ~!@#$%^&*()_+-1234567890{}[]|\:;<>?,./
- - value 3
- ' : value 4:'
- > value 5
- #value 6
- key 7' : : value 7
- " value 8 "
- ' value 9 '
-
> value '" 10
- And Fred said 'yabba dabba doo!' to Barney.
- :
- ~!@#$%^&*()_+-1234567890{}[]|\:;<>?,./
- - value 3
- ' : value 4:'
- > value 5
- #value 6
- key 7' : : value 7
- " value 8 "
- ' value 9 '
-
> value '" 10
- And Fred said 'yabba dabba doo!' to Barney.
4 changes: 2 additions & 2 deletions tests/official_tests/test_cases/list_7/load_out.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"": [
[
":",
"~!@#$%^&*()_+-1234567890{}[]|\\:;<>?,./",
"- value 3",
Expand All @@ -10,4 +10,4 @@
"' value 9 '",
"value '\" 10",
"And Fred said 'yabba dabba doo!' to Barney."
]}
]
2 changes: 1 addition & 1 deletion tests/official_tests/test_cases/string_6/load_err.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 2,
"colno": null,
"message": "unrecognized line"
"message": "unrecognized line."
}
47 changes: 24 additions & 23 deletions tests/official_tests/test_cases/string_multiline_2/dump_out.nt
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
Lorem ipsum:
>
> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
> tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
> quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
> consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
> cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
> non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
>
>
> Sed ut perspiciatis unde omnis iste natus error sit voluptatem
> accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
> illo inventore veritatis et quasi architecto beatae vitae dicta sunt
> explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit
> aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem
> sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit
> amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora
> incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad
> minima veniam, quis nostrum exercitationem ullam corporis suscipit
> laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum
> iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae
> consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
>
>
> Lorem Ipsum
>
> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
> tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
> quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
> consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
> cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
> non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
>
>
> Sed ut perspiciatis unde omnis iste natus error sit voluptatem
> accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
> illo inventore veritatis et quasi architecto beatae vitae dicta sunt
> explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit
> aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem
> sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit
> amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora
> incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad
> minima veniam, quis nostrum exercitationem ullam corporis suscipit
> laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum
> iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae
> consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
>
52 changes: 28 additions & 24 deletions tests/official_tests/test_cases/string_multiline_2/load_in.nt
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
Lorem ipsum:
>
> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
> tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
> quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
> consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
> cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
> non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
>
>
> Lorem Ipsum
>
> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
> tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
> quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
> consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
> cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
> non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
>

# Here is a bit more that one rarely sees ...
# Here is a bit more that one rarely sees ...

>
> Sed ut perspiciatis unde omnis iste natus error sit voluptatem
> accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
> illo inventore veritatis et quasi architecto beatae vitae dicta sunt
> explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit
> aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem
> sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit
> amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora
> incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad
> minima veniam, quis nostrum exercitationem ullam corporis suscipit
> laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum
> iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae
> consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
>

# There is more, but let's stop here.

>
> Sed ut perspiciatis unde omnis iste natus error sit voluptatem
> accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab
> illo inventore veritatis et quasi architecto beatae vitae dicta sunt
> explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit
> aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem
> sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit
> amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora
> incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad
> minima veniam, quis nostrum exercitationem ullam corporis suscipit
> laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum
> iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae
> consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Lorem ipsum": "\n Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, \nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo \nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse \ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat \nnon proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\n\n Sed ut perspiciatis unde omnis iste natus error sit voluptatem\naccusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab \nillo inventore veritatis et quasi architecto beatae vitae dicta sunt \nexplicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit \naut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem \nsequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit \namet, consectetur, adipisci velit, sed quia non numquam eius modi tempora \nincidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad \nminima veniam, quis nostrum exercitationem ullam corporis suscipit \nlaboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum \niure reprehenderit qui in ea voluptate velit esse quam nihil molestiae \nconsequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?\"\n"}
"\nLorem Ipsum\n\n Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, \nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo \nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse \ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat \nnon proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\n\n Sed ut perspiciatis unde omnis iste natus error sit voluptatem\naccusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab \nillo inventore veritatis et quasi architecto beatae vitae dicta sunt \nexplicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit \naut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem \nsequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit \namet, consectetur, adipisci velit, sed quia non numquam eius modi tempora \nincidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad \nminima veniam, quis nostrum exercitationem ullam corporis suscipit \nlaboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum \niure reprehenderit qui in ea voluptate velit esse quam nihil molestiae \nconsequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?\"\n"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 3,
"colno": 0,
"message": "invalid indentation"
"message": "invalid indentation."
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lineno": 3,
"colno": 0,
"message": "invalid indentation"
"message": "invalid indentation."
}
Loading

0 comments on commit 3b9ed60

Please sign in to comment.