Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add testScenario() test method #2147

Merged
merged 109 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
7f9bc29
initial project files
st-pasha Oct 13, 2022
480dce6
Added ASCII table
st-pasha Oct 13, 2022
f233839
Lexer wip
st-pasha Oct 13, 2022
bdb2cb7
Moved out Token class
st-pasha Oct 13, 2022
d586c4e
Improve Token class
st-pasha Oct 13, 2022
ffaf1e3
Clean up of the Lexer class
st-pasha Oct 13, 2022
a441b49
rename into tokenize
st-pasha Oct 13, 2022
ed2701f
better error messages
st-pasha Oct 13, 2022
42e67ef
dont abbreviate ascii character names
st-pasha Oct 14, 2022
2d2287b
added Token and ascii tests
st-pasha Oct 14, 2022
24f23db
Token.operator==
st-pasha Oct 14, 2022
219980c
added some tokenizer tests
st-pasha Oct 14, 2022
862684d
tests for modeNodeBody
st-pasha Oct 14, 2022
c3578ab
missing tests for Token
st-pasha Oct 14, 2022
e6afa75
unicode names parser for Token.character
st-pasha Oct 14, 2022
d9d9839
modeNodeBodyLine tests
st-pasha Oct 14, 2022
67ff563
ModeText tests
st-pasha Oct 14, 2022
8aa7218
ModeText tests
st-pasha Oct 14, 2022
4a703a9
expression tests
st-pasha Oct 14, 2022
941bdbc
better token names
st-pasha Oct 14, 2022
a2cfbbf
formatting
st-pasha Oct 14, 2022
5c312c2
more tests for unicode ids
st-pasha Oct 14, 2022
a062eeb
added remaining tests
st-pasha Oct 14, 2022
26bbaf8
line tags and commands
st-pasha Oct 14, 2022
9319026
format
st-pasha Oct 14, 2022
c317f86
Merge branch 'main' into ps.flame-yarn-lexer
st-pasha Oct 14, 2022
5166e29
delete changelog
st-pasha Oct 14, 2022
5111c15
rename as -> asType
st-pasha Oct 14, 2022
cbc3743
rename pos -> position
st-pasha Oct 14, 2022
75425d4
renamed codeUnit -> currentCodeUnit
st-pasha Oct 14, 2022
d55194d
unabbreviate token names
st-pasha Oct 14, 2022
577ea3f
rename pos0 -> position0
st-pasha Oct 14, 2022
4577ab7
update comments
st-pasha Oct 14, 2022
f8cb6ac
Merge branch 'ps.flame-yarn-lexer' into ps.flame-yarn-parser
st-pasha Oct 15, 2022
63cc6eb
basic classes
st-pasha Oct 15, 2022
98b2b37
Parser WIP
st-pasha Oct 15, 2022
faa3a8a
wip
st-pasha Oct 15, 2022
4e25490
literal class
st-pasha Oct 15, 2022
b3843a0
Expression class
st-pasha Oct 15, 2022
c9507ea
wip
st-pasha Oct 15, 2022
c056f9a
Concat Expression
st-pasha Oct 15, 2022
526d9f2
parse hashtag and line condition
st-pasha Oct 15, 2022
c283f7c
command class
st-pasha Oct 15, 2022
8a81035
wip
st-pasha Oct 15, 2022
3b7b0af
rename Expression class
st-pasha Oct 15, 2022
a574641
wip on parser
st-pasha Oct 16, 2022
a959ea5
add some tests for the parser
st-pasha Oct 16, 2022
c8f7712
improve error messages in the parser
st-pasha Oct 16, 2022
eceeceb
do not use templates for TypedExpression<T>
st-pasha Oct 16, 2022
ce9dde6
added a test
st-pasha Oct 16, 2022
a0ac805
renames
st-pasha Oct 16, 2022
978b142
do not allow commands in Dialogue lines
st-pasha Oct 16, 2022
67df20b
more tests
st-pasha Oct 16, 2022
47f764d
even more tests
st-pasha Oct 16, 2022
e59d3de
format
st-pasha Oct 16, 2022
41c7e99
use NameError in more cases
st-pasha Oct 16, 2022
e8a3a55
parse blocks after the options
st-pasha Oct 17, 2022
30b1574
some refactorings
st-pasha Oct 17, 2022
93b6543
if and jump commands
st-pasha Oct 17, 2022
d31b64e
stop command
st-pasha Oct 17, 2022
150599f
wait command
st-pasha Oct 17, 2022
3cad6c4
set command
st-pasha Oct 17, 2022
6a7e55f
remove _DialogueBuilder and _OptionBuilder
st-pasha Oct 17, 2022
c88e742
parser cleanup
st-pasha Oct 18, 2022
4846f40
tests
st-pasha Oct 18, 2022
5aad73e
Merge branch 'main' into ps.flame-yarn-parser
st-pasha Oct 18, 2022
8635143
Merge branch 'main' into ps.flame-yarn-parser
st-pasha Oct 19, 2022
5f44f62
format
st-pasha Oct 19, 2022
c234053
Merge branch 'main' into ps.flame-yarn-parser
st-pasha Oct 21, 2022
02cfb30
disable test
st-pasha Oct 21, 2022
8afcf42
Merge branch 'ps.flame-yarn-parser' into ps.yarn-dialogue-runner
st-pasha Oct 22, 2022
c307f18
DialogueView base class
st-pasha Oct 22, 2022
b22d325
wip on DialogueRunner
st-pasha Oct 22, 2022
a5c7784
DialogueRunner
st-pasha Oct 23, 2022
342a735
messages in exceptions are now mandatory
st-pasha Oct 23, 2022
85113b8
fix tests
st-pasha Oct 23, 2022
4fdc5a8
added tests
st-pasha Oct 23, 2022
7edd03e
tests for DialogueRunner
st-pasha Oct 23, 2022
0fb88f0
cleanup
st-pasha Oct 23, 2022
395fe79
format & analyze
st-pasha Oct 23, 2022
dc91f17
Merge branch 'main' into ps.yarn-dialogue-runner
st-pasha Oct 23, 2022
873e5fc
Added testScenario() function
st-pasha Oct 24, 2022
8f0471a
added some tests
st-pasha Oct 24, 2022
8dec3b4
more tests
st-pasha Oct 24, 2022
9978eb4
move DialogueRunner to top level
st-pasha Oct 24, 2022
eec4a75
move test
st-pasha Oct 24, 2022
64ba455
Merge branch 'main' into ps.yarn-dialogue-runner
st-pasha Oct 24, 2022
8dcfd12
update readme
st-pasha Oct 24, 2022
2965dce
doc comments for DialogueRunner
st-pasha Oct 25, 2022
59fafa3
minor
st-pasha Oct 25, 2022
ee164b4
Merge branch 'main' into ps.yarn-dialogue-runner
st-pasha Oct 25, 2022
09b174c
Merge branch 'main' into ps.yarn-integration-tests
st-pasha Oct 27, 2022
85ff100
Merge branch 'main' into ps.yarn-dialogue-runner
st-pasha Oct 27, 2022
3971921
wip
st-pasha Oct 28, 2022
99adf1e
move files to repository jenny
st-pasha Nov 1, 2022
4bed2cb
Merge branch 'main' into ps.yarn-dialogue-runner
st-pasha Nov 1, 2022
42031a9
Merge branch 'main' into ps.yarn-dialogue-runner
st-pasha Nov 3, 2022
60d6f77
tmp
st-pasha Nov 3, 2022
69c8a2e
replace repo name
st-pasha Nov 3, 2022
c9cf8ea
Merge branch 'ps.yarn-dialogue-runner' into ps.yarn-integration-tests
st-pasha Nov 3, 2022
e37ff09
move DialogueView
st-pasha Nov 3, 2022
2bf1e31
Merge branch 'ps.yarn-dialogue-runner' into ps.yarn-integration-tests
st-pasha Nov 3, 2022
ca71cfe
disable a test
st-pasha Nov 3, 2022
2cc0c86
format
st-pasha Nov 3, 2022
d3cd1d0
Merge branch 'main' into ps.yarn-integration-tests
st-pasha Nov 5, 2022
04320b9
fix a test
st-pasha Nov 5, 2022
8297ad8
remove list.md
st-pasha Nov 5, 2022
27a2744
Merge branch 'main' into ps.yarn-integration-tests
st-pasha Nov 6, 2022
38a2a5a
reenable a test
st-pasha Nov 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/flame_jenny/jenny/lib/src/parse/parse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class _Parser {
position += 1;
syntaxError('this command is only allowed after an <<if>>');
} else {
assert(token.isCommand);
assert(token.isCommand, 'unimplemented $token');
return parseUserDefinedCommand();
}
}
Expand Down Expand Up @@ -360,6 +360,7 @@ class _Parser {
// TODO(st-pasha): add verification for node existence at the end of
// project setup
target = StringLiteral(token.content);
position += 1;
} else {
take(Token.startExpression);
final expression = parseExpression();
Expand All @@ -371,13 +372,15 @@ class _Parser {
}
}
take(Token.endCommand);
take(Token.newline);
return JumpCommand(target);
}

Command parseCommandStop() {
take(Token.startCommand);
take(Token.commandStop);
take(Token.endCommand);
take(Token.newline);
return const StopCommand();
}

Expand All @@ -389,6 +392,7 @@ class _Parser {
typeError('<<wait>> command expects a numeric argument');
}
take(Token.endCommand);
take(Token.newline);
return WaitCommand(expression as NumExpression);
}

Expand Down Expand Up @@ -437,6 +441,7 @@ class _Parser {
throw UnimplementedError();
}
take(Token.endCommand);
take(Token.newline);
return SetCommand(variableName, expression);
}

Expand Down
135 changes: 123 additions & 12 deletions packages/flame_jenny/jenny/test/dialogue_runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@ import 'dart:async';
import 'package:jenny/jenny.dart';
import 'package:test/test.dart';

import 'test_scenario.dart';
import 'utils.dart';

void main() {
group('DialogueRunner', () {
test('plain dialogue', () async {
final yarn = YarnProject()
..parse('title: Hamlet\n'
'---\n'
"Bernardo: Who's there?\n"
'Francisco: Nay, answer me. Stand and unfold yourself.\n'
'Bernardo: Long live the King!\n'
'Francisco: Bernardo?\n'
'Bernardo: He\n'
'Francisco: You come most carefully upon your hour.\n'
"Bernardo: 'Tis now struck twelve. Get thee to bed, Francisco.\n"
"Francisco: For this relief much thanks. 'Tis bitter cold, "
'And I am sick at heart.\n'
'===\n');
..parse(
'-------------\n'
'title: Hamlet\n'
'-------------\n'
"Bernardo: Who's there?\n"
'Francisco: Nay, answer me. Stand and unfold yourself.\n'
'Bernardo: Long live the King!\n'
'Francisco: Bernardo?\n'
'Bernardo: He\n'
'Francisco: You come most carefully upon your hour.\n'
"Bernardo: 'Tis now struck twelve. Get thee to bed, Francisco.\n"
"Francisco: For this relief much thanks. 'Tis bitter cold, "
'And I am sick at heart.\n'
'===\n',
);
final view = _RecordingDialogueView();
final dialogue = DialogueRunner(yarnProject: yarn, dialogueViews: [view]);
await dialogue.runNode('Hamlet');
Expand Down Expand Up @@ -193,6 +197,113 @@ void main() {
),
);
});

testScenario(
testName: 'Example.plan',
input: '''
title: Start
tags:
colorID: 0
position: 592,181
---
A: Hey, I'm a character in a script!
B: And I am too! You are talking to me!
-> What's going on
A: Why this is a demo of the script system!
B: And you're in it!
-> Um ok
A: How delightful!
B: What would you prefer to do next?
-> Leave
<<jump Leave>>
-> Learn more
<<jump LearnMore>>
===
title: Leave
tags:
colorID: 0
position: 387,487
---
A: Oh, goodbye!
B: You'll be back soon!
===
title: LearnMore
tags: rawText
colorID: 0
position: 763,472
---
A: HAHAHA
===''',
testPlan: '''
line: A: Hey, I'm a character in a script!
line: B: And I am too! You are talking to me!
option: What's going on
option: Um ok
select: 1
line: A: Why this is a demo of the script system!
line: B: And you're in it!
line: A: How delightful!
line: B: What would you prefer to do next?
option: Leave
option: Learn more
select: 1
line: A: Oh, goodbye!
line: B: You'll be back soon!
''',
);

testScenario(
testName: 'Compiler.plan',
input: r'''
title: Start
---
// Compiler tests
This is a line!
<<if false>>
What what this is also a line!
<<endif>>
<<this is a custom command>>
<<set $foo to 1+2>>
<<if $foo is 3>>
Foo is 3!
<<elseif $foo is 4>>
Foo is 4!
<<else>>
Foo is something TOTALLY DIFFERENT.
<<endif>>
-> This is a shortcut option that you'll never see <<if false>>
Nice.
-> This is a different shortcut option
Sweet, but what about this?
-> It's ok
Cool.
-> Huh?
-> This is a shortcut option with no consequential text.
All done with the shortcut options!
===
''',
testPlan: '''
line: This is a line!
line: Foo is 3!
option: This is a shortcut option that you'll never see [disabled]
option: This is a different shortcut option
option: This is a shortcut option with no consequential text.
select: 2
line: Sweet, but what about this?
option: It's ok
option: Huh?
select: 1
line: Cool.
line: All done with the shortcut options!
''',
skip: true,
);
});
}

Expand Down
12 changes: 12 additions & 0 deletions packages/flame_jenny/jenny/test/parse/tokenize_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,18 @@ void main() {
);
});

test('unicode variable names', () {
expect(
() => tokenize('---\n---\n'
'{ \$эксперимент }\n'
'===\n'),
hasSyntaxError('SyntaxError: invalid variable name\n'
'> at line 3 column 3:\n'
'> { \$эксперимент }\n'
'> ^\n'),
);
});

test('invalid string', () {
expect(
() => tokenize('---\n---\n'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:test/test.dart';

import '../../test_scenario.dart';

void main() {
group('IfCommand', () {
testScenario(
testName: 'IfStatements.yarn',
input: '''
title: Start
---
<<if true>>
Player: Hey, Sally. #line:794945
Sally: Oh! Hi. #line:2dc39b
Sally: You snuck up on me. #line:34de2f
Sally: Don't do that. #line:dcc2bc
<<else>>
Player: Hey. #line:a8e70c
Sally: Hi. #line:305cde
<<endif>>
===
''',
testPlan: '''
line: Player: Hey, Sally.
line: Sally: Oh! Hi.
line: Sally: You snuck up on me.
line: Sally: Don't do that.
''',
);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'package:test/test.dart';

import '../../test_scenario.dart';

void main() {
group('SetCommand', () {
testScenario(
testName: 'AnalysisTest.plan',
input: r'''
title: Start
---
// testing
<<declare $foo = 0>> // used
<<declare $bar = 0>> // written to but never read
<<set $foo to 1>>
<<set $bar to $foo>>
{$foo} {$bar}
===
''',
testPlan: 'line: 1 1',
skip: true,
);

testScenario(
testName: 'Basic.plan',
input: r'''
title: Start
---
whoa what here's some text
<<set $foo to (1+3*3/9)-1>>
<<if $foo is 1>> // testing a comment
this should appear :)
<<if 1 is 1>>
NESTED IF BLOCK WHAAAT
<<set $foo += 47 + 6>>
<<endif>>
<<else>>
oh noooo it didn't work :(
<<endif>>
<<if $foo is 54>>
haha nice now 'set' works even when deeply nested
<<else>>
aaargh :(
<<endif>>
===
''',
testPlan: '''
line: whoa what here's some text
line: this should appear :)
line: NESTED IF BLOCK WHAAAT
line: haha nice now 'set' works even when deeply nested
''',
skip: true,
);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:test/test.dart';

import '../../test_scenario.dart';

void main() {
group('UserDefinedCommand', () {
testScenario(
testName: 'Commands.yarn',
input: '''
title: Start
---
// Testing commands
<<flip Harley3 +1>>
// Commands that begin with keywords
<<toggle>>
<<settings>>
<<iffy>>
<<nulled>>
<<orion>>
<<andorian>>
<<note>>
<<isActive>>
// Commands with a single character
<<p>>
// Commands with colons
<<hide Collision:GermOnPorch>>
===
''',
testPlan: '''
command: flip Harley3 +1
command: toggle
command: settings
command: iffy
command: nulled
command: orion
command: andorian
command: note
command: isActive
command: p
command: hide Collision:GermOnPorch
''',
skip: true,
);
});
}
Loading