Fixed route test cases

This commit is contained in:
thomashii@dukefirehawk.com 2021-05-11 20:11:23 +08:00
parent 25af334f4d
commit 7d5e75e440
6 changed files with 22 additions and 14 deletions

View file

@ -43,7 +43,7 @@ class _Chain<T> extends ListParser<T> {
@override
ParseResult<List<T>> __parse(ParseArgs args) {
var errors = <SyntaxError>[];
var results = <T?>[];
var results = <T>[];
var spans = <FileSpan>[];
bool successful = true;
@ -62,9 +62,14 @@ class _Chain<T> extends ListParser<T> {
}
//TODO: To be looked at
//if (result.value != null) {
results.add(result.value);
//}
if (result.value != null) {
//print(result.value.runtimeType);
results.add(result.value!);
} else {
//print("Add NULL");
// Add dummy "NULL" String
results.add("NULL" as T);
}
if (result.span != null) {
spans.add(result.span!);

View file

@ -7,7 +7,6 @@ import 'package:matcher/matcher.dart';
import 'package:source_span/source_span.dart';
import 'package:string_scanner/string_scanner.dart';
import 'package:tuple/tuple.dart';
import 'package:optional/optional.dart';
import '../error.dart';
part 'any.dart';
@ -199,7 +198,7 @@ abstract class Parser<T> {
}
var preceding = v.isEmpty ? [] : (v[0] == null ? [] : [v[0]]);
var out = List<T>.from(preceding);
if (v[1] != null) {
if (v[1] != null && v[1] != "NULL") {
v[1].forEach((element) {
out.add(element as T);
});

View file

@ -8,7 +8,7 @@ class _Index<T> extends Parser<T> {
@override
ParseResult<T> __parse(ParseArgs args) {
ParseResult<List<T>?> result = parser._parse(args.increaseDepth());
ParseResult<List<T>> result = parser._parse(args.increaseDepth());
Object? value;
if (result.successful) {

View file

@ -15,6 +15,5 @@ dependencies:
source_span: ^1.8.1
string_scanner: ^1.1.0
tuple: ^2.0.0
optional: ^6.0.0-nullsafety.2
dev_dependencies:
test: ^1.17.3

View file

@ -20,7 +20,12 @@ class RouteGrammar {
regExp.opt(),
]).map((r) {
var match = r.value![0] as Match;
var rgxMatch = r.value![2] as Match?;
var r2 = r.value![2];
Match? rgxMatch;
if (r2 != 'NULL') {
rgxMatch = r2 as Match?;
}
var pre = match[1] ?? '';
var post = match[3] ?? '';

View file

@ -7,11 +7,11 @@ environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
combinator:
path: ../combinator
# git:
# url: https://github.com/dukefirehawk/angel.git
# ref: sdk-2.12.x_nnbd
# path: packages/combinator
# path: ../combinator
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/combinator
string_scanner: ^1.0.0
dev_dependencies:
build_runner: ^1.11.5