Skip to content

Commit

Permalink
dev.3
Browse files Browse the repository at this point in the history
  • Loading branch information
f3ath committed Jul 29, 2020
1 parent d378406 commit aae75ac
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## [Unreleased]
## [0.0.0+dev.3] - 2020-07-28
### Added
- Partial implementation of bracket field notation

## [0.0.0+dev.2] - 2020-07-28
### Added
- Recursive selector
Expand All @@ -13,6 +17,7 @@
### Added
- Basic design draft

[Unreleased]: https://github.com/f3ath/jessie/compare/0.0.0+dev.2...HEAD
[Unreleased]: https://github.com/f3ath/jessie/compare/0.0.0+dev.3...HEAD
[0.0.0+dev.3]: https://github.com/f3ath/jessie/compare/0.0.0+dev.2...0.0.0+dev.3
[0.0.0+dev.2]: https://github.com/f3ath/jessie/compare/0.0.0+dev.1...0.0.0+dev.2
[0.0.0+dev.1]: https://github.com/f3ath/jessie/compare/0.0.0+dev.0...0.0.0+dev.1
3 changes: 3 additions & 0 deletions lib/src/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ class Ready implements State {
final node = nodes.single;
if (node.value == '*') return AllInArray();
if (node.isNumber) return Index(int.parse(nodes.first.value));
if (node.value.startsWith("'")) return Field(_unquote(node.value));
throw StateError('Unexpected bracket expression');
}

String _unquote(String s) => s.substring(1, s.length - 1);
}

class AwaitingField implements State {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_path
version: 0.0.0+dev.2
version: 0.0.0+dev.3
description: JSONPath for Dart. JSONPath is XPath for JSON. It is a path in a JSON document.
homepage: "https://github.com/f3ath/jessie"

Expand Down
14 changes: 14 additions & 0 deletions test/json_path_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ void main() {
expect(store.select(json).single.value, json['store']);
expect(store.select(json).single.path, r"$['store']");
});

test('Single field in bracket notation', () {
final store = JsonPath(r"$['store']");
expect(store.toString(), r"$['store']");
expect(store.select(json).single.value, json['store']);
expect(store.select(json).single.path, r"$['store']");
});

test('Mixed brackets and fields', () {
final store = JsonPath(r"$['store'].bicycle['price']");
expect(store.toString(), r"$['store']['bicycle']['price']");
expect(store.select(json).single.value, json['store']['bicycle']['price']);
expect(store.select(json).single.path, r"$['store']['bicycle']['price']");
});
});

group('Wildcards', () {
Expand Down

0 comments on commit aae75ac

Please sign in to comment.