Skip to content

Commit 701cd17

Browse files
authored
v0.6.3 (#76)
1 parent 77a673a commit 701cd17

12 files changed

+62
-36
lines changed

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.6.3] - 2023-08-26
8+
### Fixed
9+
- Allow whitespaces after `?` in expressions
10+
711
## [0.6.2] - 2023-07-21
812
### Fixed
913
- Disallow comparison of non-singular queries
@@ -160,6 +164,7 @@ Previously, no modification would be made and no errors/exceptions thrown.
160164
### Added
161165
- Basic design draft
162166

167+
[0.6.3]: https://github.com/f3ath/jessie/compare/0.6.2...0.6.3
163168
[0.6.2]: https://github.com/f3ath/jessie/compare/0.6.1...0.6.2
164169
[0.6.1]: https://github.com/f3ath/jessie/compare/0.6.0...0.6.1
165170
[0.6.0]: https://github.com/f3ath/jessie/compare/0.5.3...0.6.0

Diff for: lib/src/expression/static_expression.dart

+4-6
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ class StaticExpression<T extends Object> extends Expression<T> {
1212

1313
@override
1414
Expression<R> merge<R extends Object, M extends Object>(
15-
Expression<M> other, R Function(T v, M m) merger) {
16-
if (other is StaticExpression<M>) {
17-
return StaticExpression(merger(value, other.value));
18-
}
19-
return super.merge(other, merger);
20-
}
15+
Expression<M> other, R Function(T v, M m) merger) =>
16+
other is StaticExpression<M>
17+
? StaticExpression(merger(value, other.value))
18+
: super.merge(other, merger);
2119
}

Diff for: lib/src/fun/fun_factory.dart

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class FunFactory {
3636
if (args.length == 1) return any1<T>(name, args[0]);
3737
if (args.length == 2) return any2<T>(name, args[0], args[1]);
3838
} on TypeError catch (e) {
39-
/// Thrown by
4039
throw FormatException('Invalid argument: $e');
4140
} on StateError catch (e) {
4241
throw FormatException(e.message);

Diff for: lib/src/grammar/cmp_operator.dart

-4
This file was deleted.

Diff for: lib/src/grammar/compare.dart

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:maybe_just_nothing/maybe_just_nothing.dart';
2+
import 'package:petitparser/petitparser.dart';
23

34
/// True if [a] equals [b].
45
bool _eq(Maybe a, Maybe b) =>
@@ -48,3 +49,5 @@ const _operations = <String, bool Function(Maybe, Maybe)>{
4849

4950
bool compare(String op, Maybe a, Maybe b) =>
5051
(_operations[op] ?? (throw StateError('Invalid operation "$op"')))(a, b);
52+
53+
final cmpOperator = _operations.keys.map(string).toChoiceParser().trim();

Diff for: lib/src/grammar/comparison_expression.dart

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:json_path/src/expression/expression.dart';
2-
import 'package:json_path/src/grammar/cmp_operator.dart';
32
import 'package:json_path/src/grammar/compare.dart';
43
import 'package:maybe_just_nothing/maybe_just_nothing.dart';
54
import 'package:petitparser/parser.dart';

Diff for: lib/src/grammar/json_path.dart

+4-6
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,18 @@ class JsonPathGrammarDefinition extends GrammarDefinition<Expression<Nodes>> {
5757
.skip(before: string('..'))
5858
.map((value) => sequenceSelector([selectAllRecursively, value]));
5959

60-
Parser<Expression<bool>> _parenExpr() => negatable(
61-
_logicalExpr().inParens(),
62-
);
60+
Parser<Expression<bool>> _parenExpr() => negatable(_logicalExpr().inParens());
6361

6462
Parser<Expression> _funArgument() => [
6563
literal,
6664
_filterPath(),
6765
ref0(_funExpr),
6866
].toChoiceParser().trim();
6967

70-
Parser<T> _funCall<T>(T Function(FunCall) funMaker) =>
68+
Parser<T> _funCall<T>(T Function(FunCall) toFun) =>
7169
(funName & _funArgument().toList().inParens())
7270
.map((v) => FunCall(v[0], v[1]))
73-
.tryMap(funMaker);
71+
.tryMap(toFun);
7472

7573
Parser<Expression> _funExpr() => _funCall(_fun.any);
7674

@@ -125,7 +123,7 @@ class JsonPathGrammarDefinition extends GrammarDefinition<Expression<Nodes>> {
125123
].toChoiceParser());
126124

127125
Parser<Selector> _expressionFilter() =>
128-
_logicalExpr().skip(before: string('?')).map(filterSelector);
126+
_logicalExpr().skip(before: string('?').trim()).map(filterSelector);
129127

130128
Parser<Selector> _segment() => [
131129
dotName,

Diff for: lib/src/grammar/slice_indices.dart

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ Iterable<int> _backward(int length, int? start, int? stop, int step) sync* {
2222
}
2323

2424
/// exclusive
25-
int _low(int? stop, int length) {
26-
if (stop == null) return -1;
27-
if (stop < 0) return max(length + stop, -1);
28-
return stop;
29-
}
25+
int _low(int? stop, int length) => switch (stop) {
26+
null => -1,
27+
< 0 => max(length + stop, -1),
28+
_ => stop,
29+
};
3030

3131
/// inclusive
32-
int _high(int? start, int length) {
33-
if (start == null) return length - 1;
34-
if (start < 0) return length + start;
35-
return min(start, length - 1);
36-
}
32+
int _high(int? start, int length) => switch (start) {
33+
null => length - 1,
34+
< 0 => length + start,
35+
_ => min(start, length - 1),
36+
};

Diff for: pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_path
2-
version: 0.6.2
2+
version: 0.6.3
33
description: Implementation of JSONPath expressions like "$.store.book[2].price". Reads and writes values in parsed JSON objects.
44
homepage: "https://github.com/f3ath/jessie"
55

Diff for: test/cases/standard/basic.json

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
"result": ["A", "B"],
4444
"paths": ["$['a']", "$['b']"],
4545
"pointers": ["/a", "/b"]
46+
}, {
47+
"name": "union wildcard on object, twice",
48+
"selector": "$[*, *]",
49+
"document": {"a": "A", "b": "B"},
50+
"result": ["A", "B", "A", "B"]
4651
}, {
4752
"name": "dot wildcard on array",
4853
"selector": "$.*",

Diff for: test/cases/standard/whitespace.json

+25-1
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,34 @@
4343
"result": [ "foo" ]
4444
},
4545
{
46-
"name": "returns in an absolute singular selector ",
46+
"name": "returns in an absolute singular selector",
4747
"selector" : "$..[?length(@)==length($\r[0]\r.a)]",
4848
"document" : [ {"a": "foo"}, {} ],
4949
"result": [ "foo" ]
50+
},
51+
{
52+
"name": "space between ? and function",
53+
"selector" : "$..[? length(@)==1]",
54+
"document" : [ {"a": "foo"}, {} ],
55+
"result": [ {"a": "foo"} ]
56+
},
57+
{
58+
"name": "tab between ? and function",
59+
"selector" : "$..[?\tlength(@)==1]",
60+
"document" : [ {"a": "foo"}, {} ],
61+
"result": [ {"a": "foo"} ]
62+
},
63+
{
64+
"name": "\\n between ? and function",
65+
"selector" : "$..[ ?\nlength(@) == 1 ]",
66+
"document" : [ {"a": "foo"}, {} ],
67+
"result": [ {"a": "foo"} ]
68+
},
69+
{
70+
"name": "\\r between ? and function",
71+
"selector" : "$..[ ?\rlength(@) == 1 ]",
72+
"document" : [ {"a": "foo"}, {} ],
73+
"result": [ {"a": "foo"} ]
5074
}
5175
]
5276
}

Diff for: test/helper.dart

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import 'package:path/path.dart' as path;
66
import 'package:test/test.dart';
77

88
void runTestsInDirectory(String dirName, {JsonPathParser? parser}) {
9-
JsonPath jsonPath(String expression) {
10-
if (parser != null) return parser.parse(expression);
11-
return JsonPath(expression);
12-
}
9+
JsonPath jsonPath(String expression) =>
10+
parser?.parse(expression) ?? JsonPath(expression);
1311

1412
Directory(dirName)
1513
.listSync()
@@ -26,11 +24,12 @@ void runTestsInDirectory(String dirName, {JsonPathParser? parser}) {
2624
}
2725
}
2826

27+
final String selector = t['selector'];
28+
2929
final document = t['document'];
3030
final String? name = t['name'];
3131
final List? paths = t['paths'];
3232
final List? pointers = t['pointers'];
33-
final String selector = t['selector'];
3433
final String? skip = t['skip'];
3534
final List? values = t['result'];
3635
final bool? invalid = t['invalid_selector'];
@@ -66,7 +65,7 @@ void runTestsInDirectory(String dirName, {JsonPathParser? parser}) {
6665
);
6766
});
6867
}
69-
if ([values, paths, pointers, invalid].every((_) => _ == null)) {
68+
if ([values, paths, pointers, invalid].every((v) => v == null)) {
7069
throw ArgumentError('No expectations found');
7170
}
7271
}, skip: skip);

0 commit comments

Comments
 (0)