2828import org .antlr .runtime .RecognitionException ;
2929import org .junit .Before ;
3030import org .junit .Test ;
31+ import org .metafacture .commons .reflection .ReflectionException ;
3132import org .metafacture .flux .parser .FluxProgramm ;
3233
3334/**
@@ -54,7 +55,7 @@ public void setup() {
5455 @ Test
5556 public void shouldAllowEmptyCommentInLastLineOfFile ()
5657 throws RecognitionException , IOException {
57- final String script = "\" test\" |write( \" stdout \" ) ; //" ;
58+ final String script = "\" test\" |print ; //" ;
5859
5960 FluxCompiler .compile (createInputStream (script ), emptyMap ());
6061
@@ -65,7 +66,7 @@ public void shouldAllowEmptyCommentInLastLineOfFile()
6566 @ Test
6667 public void shouldAllowEmptyCommentInFile ()
6768 throws RecognitionException , IOException {
68- final String script = "\" test\" |write( \" stdout \" ) ; //\n " ;
69+ final String script = "\" test\" |print ; //\n " ;
6970
7071 FluxCompiler .compile (createInputStream (script ), emptyMap ());
7172
@@ -78,7 +79,7 @@ public void shouldReplaceJavaEscapeSequences()
7879 throws IOException , RecognitionException {
7980 final String script =
8081 "\" quot=\\ \" octal1=\\ 7 octal2=\\ 60 octal3=\\ 103 unicode=\\ u00f8 tab=[\\ t]\" " +
81- "|write( \" stdout \" ) ;" ;
82+ "|print ;" ;
8283
8384 final FluxProgramm program = FluxCompiler .compile (
8485 createInputStream (script ), emptyMap ());
@@ -89,6 +90,103 @@ public void shouldReplaceJavaEscapeSequences()
8990 stdoutBuffer .toString ());
9091 }
9192
93+ @ Test (expected = FluxParseException .class )
94+ public void issue421_shouldThrowFluxParseExceptionWhenSemicolonInFlowIsMissing ()
95+ throws RecognitionException , IOException {
96+ final String script = "\" test\" |print" ;
97+ try {
98+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
99+ } catch (FluxParseException fpe ) {
100+ assertEquals ("mismatched input '<EOF>' expecting ';' in Flux" , fpe .getMessage ());
101+ throw fpe ;
102+ }
103+ }
104+
105+ @ Test (expected = FluxParseException .class )
106+ public void issue421_shouldThrowFluxParseExceptionWhenSemicolonInVarDefIsMissing ()
107+ throws RecognitionException , IOException {
108+ final String script = "foo=42" ;
109+ try {
110+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
111+ } catch (FluxParseException re ) {
112+ assertEquals ("mismatched input '<EOF>' expecting ';' in Flux" , re .getMessage ());
113+ throw re ;
114+ }
115+ }
116+
117+ @ Test (expected = ReflectionException .class )
118+ public void issue421_shouldThrowReflectionExceptionWhenCommandIsNotFound ()
119+ throws RecognitionException , IOException {
120+ final String script = "\" test\" |prin;" ;
121+ try {
122+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
123+ } catch (ReflectionException re ) {
124+ assertEquals ("Class not found: prin" , re .getMessage ());
125+ throw re ;
126+ }
127+ }
128+
129+ @ Test (expected = FluxParseException .class )
130+ public void issue421_shouldThrowFluxParseExceptionWhenInputIsMissingAfterPipe1 ()
131+ throws RecognitionException , IOException {
132+ final String script = "\" test\" |" ;
133+ try {
134+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
135+ } catch (FluxParseException re ) {
136+ assertEquals ("no viable alternative at input '<EOF>' in Flux" , re .getMessage ());
137+ throw re ;
138+ }
139+ }
140+
141+ @ Test (expected = FluxParseException .class )
142+ public void issue421_shouldThrowFluxParseExceptionWhenInputIsMissingAfterPipe2 ()
143+ throws RecognitionException , IOException {
144+ final String script = "\" test\" |;" ;
145+ try {
146+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
147+ } catch (FluxParseException re ) {
148+ assertEquals ("no viable alternative at input ';' in Flux" , re .getMessage ());
149+ throw re ;
150+ }
151+ }
152+
153+ @ Test (expected = FluxParseException .class )
154+ public void issue421_shouldThrowFluxParseExceptionWhenTeeStructureOccursWithouATeeCommand ()
155+ throws RecognitionException , IOException {
156+ final String script = "\" test\" |{print}{print} ;" ;
157+ try {
158+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
159+ } catch (FluxParseException re ) {
160+ assertEquals ("Flow cannot be split without a tee-element." , re .getMessage ());
161+ throw re ;
162+ }
163+ }
164+
165+ @ Test (expected = FluxParseException .class )
166+ public void issue421_shouldThrowFluxParseExceptionWhenTeeIsNotASender ()
167+ throws RecognitionException , IOException {
168+ final String script = "\" test\" |print|object-tee|{print}{print} ;" ;
169+ try {
170+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
171+ } catch (FluxParseException re ) {
172+ assertEquals ("org.metafacture.io.ObjectStdoutWriter is not a sender" , re .getMessage ());
173+ throw re ;
174+ }
175+ }
176+
177+ @ Test (expected = FluxParseException .class )
178+ public void issue421_shouldInsertMissingSymbolsWhenTeeIsStructurallyInvalid ()
179+ throws RecognitionException , IOException {
180+ final String script = "\" test\" |object-tee|{object-tee{print{print} ;" ;
181+ try {
182+ FluxCompiler .compile (createInputStream (script ), emptyMap ());
183+ String tmp =stdoutBuffer .toString ();
184+ } catch (FluxParseException re ) {
185+ assertEquals ("missing '}' at '{' in Flux" , re .getMessage ());
186+ throw re ;
187+ }
188+ }
189+
92190 private ByteArrayInputStream createInputStream (String script ) {
93191 return new ByteArrayInputStream (script .getBytes (StandardCharsets .UTF_8 ));
94192 }
0 commit comments