28
28
import org .antlr .runtime .RecognitionException ;
29
29
import org .junit .Before ;
30
30
import org .junit .Test ;
31
+ import org .metafacture .commons .reflection .ReflectionException ;
31
32
import org .metafacture .flux .parser .FluxProgramm ;
32
33
33
34
/**
@@ -54,7 +55,7 @@ public void setup() {
54
55
@ Test
55
56
public void shouldAllowEmptyCommentInLastLineOfFile ()
56
57
throws RecognitionException , IOException {
57
- final String script = "\" test\" |write( \" stdout \" ) ; //" ;
58
+ final String script = "\" test\" |print ; //" ;
58
59
59
60
FluxCompiler .compile (createInputStream (script ), emptyMap ());
60
61
@@ -65,7 +66,7 @@ public void shouldAllowEmptyCommentInLastLineOfFile()
65
66
@ Test
66
67
public void shouldAllowEmptyCommentInFile ()
67
68
throws RecognitionException , IOException {
68
- final String script = "\" test\" |write( \" stdout \" ) ; //\n " ;
69
+ final String script = "\" test\" |print ; //\n " ;
69
70
70
71
FluxCompiler .compile (createInputStream (script ), emptyMap ());
71
72
@@ -78,7 +79,7 @@ public void shouldReplaceJavaEscapeSequences()
78
79
throws IOException , RecognitionException {
79
80
final String script =
80
81
"\" quot=\\ \" octal1=\\ 7 octal2=\\ 60 octal3=\\ 103 unicode=\\ u00f8 tab=[\\ t]\" " +
81
- "|write( \" stdout \" ) ;" ;
82
+ "|print ;" ;
82
83
83
84
final FluxProgramm program = FluxCompiler .compile (
84
85
createInputStream (script ), emptyMap ());
@@ -89,6 +90,103 @@ public void shouldReplaceJavaEscapeSequences()
89
90
stdoutBuffer .toString ());
90
91
}
91
92
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
+
92
190
private ByteArrayInputStream createInputStream (String script ) {
93
191
return new ByteArrayInputStream (script .getBytes (StandardCharsets .UTF_8 ));
94
192
}
0 commit comments