Skip to content

Commit

Permalink
issue #12: Added some SUBTRACT statement tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
wiztigers committed Jul 20, 2015
1 parent 40a9edb commit 7d2dfee
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--- Code Elements ---
[[SubtractStatement]] [1,8:SUBTRACT]<SUBTRACT> --> [17,17:x]<UserDefinedWord>

[[SentenceEnd]] [18,18+:.]<PeriodSeparator> --> [18,18+:.]<PeriodSeparator>

[[SubtractStatement]] [1,8:SUBTRACT]<SUBTRACT> --> [25,28:toto]<UserDefinedWord>

[[SentenceEnd]] [29,29+:.]<PeriodSeparator> --> [29,29+:.]<PeriodSeparator>

[[SubtractStatement]] [1,8:SUBTRACT]<SUBTRACT> --> [24,27:toto]<UserDefinedWord>

[[SentenceEnd]] [28,28+:.]<PeriodSeparator> --> [28,28+:.]<PeriodSeparator>

[[SubtractStatement]] [1,8:SUBTRACT]<SUBTRACT> --> [28,28:x]<UserDefinedWord>

[[SentenceEnd]] [1,1+:.]<PeriodSeparator> --> [1,1+:.]<PeriodSeparator>

[[SubtractStatement]] [1,8:SUBTRACT]<SUBTRACT> --> [17,17:x]<UserDefinedWord>

[[SentenceEnd]] [18,18+:.]<PeriodSeparator> --> [18,18+:.]<PeriodSeparator>

[[SubtractStatement]] [1,8:SUBTRACT]<SUBTRACT> --> [19,22:toto]<UserDefinedWord>

[[SentenceEnd]] [23,23+:.]<PeriodSeparator> --> [23,23+:.]<PeriodSeparator>

[[SubtractStatement]] [1,8:SUBTRACT]<SUBTRACT> --> [23,26:toto]<UserDefinedWord>

[[SentenceEnd]] [27,27+:.]<PeriodSeparator> --> [27,27+:.]<PeriodSeparator>

This comment has been minimized.

Copy link
@wiztigers

wiztigers Jul 21, 2015

Contributor

This tests recognized tokens. Each token has a starting character and an ending character.
Here you have an alternance of :

  • statements (always SUBSTRACT statement as that's I am testing)
  • END statement special characters (notice that Sentence and is only one char long: that's ".").

I don't test syntax errors (bad! no twinkie for me!), so there's only a --- Code Elements --- section, and no --- Diagnostics --- section.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
x = a x -
toto = titi tata + toto -
x = a b + ab + x -, toto = a b + ab + toto -
x = a x -
x = 1 x -
toto = 1 2 + toto -
x = 1 2 + 3 + x -, toto = 1 2 + 3 + toto -

This comment has been minimized.

Copy link
@wiztigers

wiztigers Jul 21, 2015

Contributor

SubstractStatement does have a Reverse Polish Notation (RPN)-like ToString method. This allows me to test RPN notations in a second TypeCobol.Test/Compiler/Parser/ResultFiles/*.text file.

... There's not many cases that are tested ! And no syntax error cases ! Booh!

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
* //////////////
* // SUBTRACT //
* //////////////

* FORMAT 1
* IDENTIFIERS
SUBTRACT a FROM x.
SUBTRACT titi tata FROM toto.
SUBTRACT a b ab FROM x toto.
SUBTRACT
a
FROM x
.
* LITERALS
SUBTRACT 1 FROM x.
SUBTRACT 1 2 FROM toto.
SUBTRACT 1 2 3 FROM x toto.

This comment has been minimized.

Copy link
@wiztigers

wiztigers Jul 21, 2015

Contributor

That's my COBOL test source file.
Notice the comments : you should write the intent behind each group of tests, for future reference.

16 changes: 15 additions & 1 deletion TypeCobol.Test/Compiler/Parser/TestCodeElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ public static void Check_EntryCodeElements()

public static void Check_StatementCodeElements()
{
Check_ADDCodeElements();
Check_ADDCodeElements();
Check_SUBTRACTCodeElements();
}

public static void Check_ADDCodeElements()
Expand All @@ -246,5 +247,18 @@ public static void Check_ADDCodeElements()
string result = ParserUtils.DumpCodeElements(unit);
ParserUtils.CheckWithResultFile(result, "Statements" + Path.DirectorySeparatorChar + "ADDCodeElements");
}

public static void Check_SUBTRACTCodeElements()
{
DocumentFormat format = new DocumentFormat(Encoding.UTF8, EndOfLineDelimiter.CrLfCharacters, 0, ColumnsLayout.FreeTextFormat);
CompilationUnit unit = ParserUtils.ParseCobolFile("Statements" + Path.DirectorySeparatorChar + "SUBTRACTCodeElements", format);

string path = "Compiler" + Path.DirectorySeparatorChar + "Parser" + Path.DirectorySeparatorChar + "ResultFiles" + Path.DirectorySeparatorChar + "Statements";
ArithmeticStatementTester tester = new ArithmeticStatementTester();
tester.CompareWithRPNFile(unit.SyntaxDocument, path + Path.DirectorySeparatorChar + "SUBTRACTRPN.txt");

string result = ParserUtils.DumpCodeElements(unit);
ParserUtils.CheckWithResultFile(result, "Statements" + Path.DirectorySeparatorChar + "SUBTRACTCodeElements");
}
}
}

This comment has been minimized.

Copy link
@wiztigers

wiztigers Jul 21, 2015

Contributor

Here's the C# "glue" between Sample source code and ResultFiles expected results.
Depending on the test, your shouldn't have to write much and should be able to reuse utility test methods from other similar tests.

This commit is from an early phase of the project ; I assume we'll later be able to automatically detect source and expected result files so you won't have to write C# glue anymore.

3 changes: 3 additions & 0 deletions TypeCobol.Test/TypeCobol.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
<Content Include="Compiler\Parser\ResultFiles\ONCodeElements.txt" />
<Content Include="Compiler\Parser\ResultFiles\PERFORMCodeElements.txt" />
<Content Include="Compiler\Parser\ResultFiles\Statements\ADDRPN.txt" />
<Content Include="Compiler\Parser\ResultFiles\Statements\SUBTRACTCodeElements.txt" />
<Content Include="Compiler\Parser\ResultFiles\Statements\SUBTRACTRPN.txt" />
<Content Include="Compiler\Parser\ResultFiles\WHENCodeElements.txt" />
<Content Include="Compiler\Parser\ResultFiles\HeaderCodeElements.txt" />
<Content Include="Compiler\Parser\ResultFiles\XMLCodeElements.txt" />
Expand Down Expand Up @@ -191,6 +193,7 @@
<None Include="Compiler\Parser\Samples\HeaderCodeElements.cbl" />
<None Include="Compiler\Parser\Samples\IDCodeElements.cbl" />
<None Include="Compiler\Parser\Samples\ONCodeElements.cbl" />
<None Include="Compiler\Parser\Samples\Statements\SUBTRACTCodeElements.cbl" />
<None Include="Compiler\Parser\Samples\WHENCodeElements.cbl" />
<None Include="Compiler\Parser\Samples\XMLCodeElements.cbl" />
<None Include="Compiler\Parser\Samples\UDWCodeElements.cbl" />

This comment has been minimized.

Copy link
@wiztigers

wiztigers Jul 21, 2015

Contributor

We added some files, so the new visual studio settings have to be commited.
This .csproj file should be automagically generated by visual studio, but don't forget to commit it so your friends don't get compile errors !

Expand Down

1 comment on commit 7d2dfee

@wiztigers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, listen !
Notice that I've referenced the linked issue in my commit comment. That's how you should do it, too. Write info once, get it in multiple supports, and track it forever.

Please sign in to comment.