| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE.md file. | |
| 4 | |
| 5 import 'dart:async' show | |
| 6 Future; | |
| 7 | |
| 8 import 'package:fletchc/src/hub/sentence_parser.dart'; | |
| 9 | |
| 10 import 'package:expect/expect.dart'; | |
| 11 | |
| 12 Future main() { | |
| 13 Sentence sentence; | |
| 14 | |
| 15 void checkAction(String name) { | |
| 16 Expect.isNotNull(sentence.verb); | |
| 17 Expect.stringEquals(name, sentence.verb.name); | |
| 18 print("Action '$name' as expected."); | |
| 19 } | |
| 20 | |
| 21 void checkTarget(TargetKind kind) { | |
| 22 Expect.isNotNull(sentence.targets.single); | |
| 23 Expect.equals(kind, sentence.targets.single.kind); | |
| 24 print("Target '$kind' as expected."); | |
| 25 } | |
| 26 | |
| 27 void checkNamedTarget(TargetKind kind, String name) { | |
| 28 Expect.isNotNull(sentence.targets.single); | |
| 29 NamedTarget namedTarget = sentence.targets.single; | |
| 30 Expect.equals(kind, namedTarget.kind); | |
| 31 Expect.stringEquals(name, namedTarget.name); | |
| 32 print("NamedTarget '$kind $name' as expected."); | |
| 33 } | |
| 34 | |
| 35 void checkNoTarget() { | |
| 36 Expect.isTrue(sentence.targets.isEmpty); | |
| 37 print("No target as expected."); | |
| 38 } | |
| 39 | |
| 40 sentence = parseSentence([]); | |
| 41 print(sentence); | |
| 42 checkAction('help'); | |
| 43 Expect.isTrue(sentence.prepositions.isEmpty); | |
| 44 checkNoTarget(); | |
| 45 Expect.isNull(sentence.trailing); | |
| 46 | |
| 47 sentence = parseSentence(['not_a_verb']); | |
| 48 print(sentence); | |
| 49 checkAction('not_a_verb'); | |
| 50 Expect.isTrue(sentence.prepositions.isEmpty); | |
| 51 checkNoTarget(); | |
| 52 Expect.isNotNull(sentence.trailing); | |
| 53 Expect.listEquals(['not_a_verb'], sentence.trailing); | |
| 54 | |
| 55 sentence = parseSentence(['create', 'session', 'fisk']); | |
| 56 print(sentence); | |
| 57 checkAction('create'); | |
| 58 Expect.isTrue(sentence.prepositions.isEmpty); | |
| 59 checkNamedTarget(TargetKind.SESSION, 'fisk'); | |
| 60 Expect.isNull(sentence.trailing); | |
| 61 | |
| 62 void checkCreateFooInFisk() { | |
| 63 Expect.isNotNull(sentence.verb); | |
| 64 Expect.stringEquals('create', sentence.verb.name); | |
| 65 Preposition preposition = sentence.prepositions.single; | |
| 66 Expect.isNotNull(preposition); | |
| 67 Expect.equals(PrepositionKind.IN, preposition.kind); | |
| 68 NamedTarget namedTarget = preposition.target; | |
| 69 Expect.isNotNull(namedTarget); | |
| 70 Expect.equals(TargetKind.SESSION, namedTarget.kind); | |
| 71 Expect.stringEquals('fisk', namedTarget.name); | |
| 72 checkNamedTarget(TargetKind.CLASS, 'Foo'); | |
| 73 Expect.isNull(sentence.trailing); | |
| 74 } | |
| 75 sentence = parseSentence(['create', 'in', 'session', 'fisk', 'class', 'Foo']); | |
| 76 print(sentence); | |
| 77 checkCreateFooInFisk(); | |
| 78 | |
| 79 sentence = parseSentence(['create', 'class', 'Foo', 'in', 'session', 'fisk']); | |
| 80 print(sentence); | |
| 81 checkCreateFooInFisk(); | |
| 82 | |
| 83 sentence = parseSentence(['create', 'in', 'fisk']); | |
| 84 print(sentence); | |
| 85 checkAction('create'); | |
| 86 Expect.isNotNull(sentence.prepositions.single); | |
| 87 Expect.equals(PrepositionKind.IN, sentence.prepositions.single.kind); | |
| 88 Expect.isTrue(sentence.prepositions.single.target is ErrorTarget); | |
| 89 checkNoTarget(); | |
| 90 Expect.isNull(sentence.trailing); | |
| 91 | |
| 92 sentence = parseSentence(['create', 'in', 'fisk', 'fisk']); | |
| 93 print(sentence); | |
| 94 checkAction('create'); | |
| 95 Expect.isNotNull(sentence.prepositions.single); | |
| 96 Expect.equals(PrepositionKind.IN, sentence.prepositions.single.kind); | |
| 97 Expect.isTrue(sentence.prepositions.single.target is ErrorTarget); | |
| 98 checkNoTarget(); | |
| 99 Expect.isNotNull(sentence.trailing); | |
| 100 Expect.listEquals(['fisk'], sentence.trailing); | |
| 101 | |
| 102 sentence = parseSentence(['help', 'all']); | |
| 103 print(sentence); | |
| 104 checkAction('help'); | |
| 105 Expect.isTrue(sentence.prepositions.isEmpty); | |
| 106 checkTarget(TargetKind.ALL); | |
| 107 Expect.isNull(sentence.trailing); | |
| 108 | |
| 109 return new Future.value(); | |
| 110 } | |
| OLD | NEW |