Skip to content

Commit

Permalink
added static token
Browse files Browse the repository at this point in the history
  • Loading branch information
synapticloop committed Feb 4, 2017
1 parent b3ae7b3 commit e91bccc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/main/java/synapticloop/templar/token/StaticToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public StaticToken(String value, StringTokenizer stringTokenizer, Tokeniser toke
}

private void readContents() throws ParseException {
StringBuilder stringBuilder = new StringBuilder();

boolean foundFilePath = true;
boolean foundClassPath = true;
Expand All @@ -81,7 +80,7 @@ private void readContents() throws ParseException {
bufferedReader = new BufferedReader(new FileReader(templarFile));
String line = null;
while((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line + "\n");
staticContents.append(line + "\n");
}
} catch(IOException jiioex) {
throw new ParseException("IO Exception reading file '" + templarFile.getPath() + "'", jiioex);
Expand All @@ -108,7 +107,7 @@ private void readContents() throws ParseException {
String line = null;
try {
while((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line + "\n");
staticContents.append(line + "\n");
}
} catch(IOException jiioex) {
foundClassPath = false;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/synapticloop/templar/utils/Tokeniser.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class Tokeniser implements Serializable {
TOKEN_MAP.put("endif", ENDIF);
TOKEN_MAP.put("endloop", ENDLOOP);
TOKEN_MAP.put("import", IMPORT);
TOKEN_MAP.put("static", STATIC);
TOKEN_MAP.put("pre", PRE);
TOKEN_MAP.put("requires", REQUIRES);
}
Expand Down
47 changes: 47 additions & 0 deletions src/test/java/synapticloop/templar/token/StaticTokenTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package synapticloop.templar.token;

/*
* Copyright (c) 2012-2017 synapticloop.
* All rights reserved.
*
* This source code and any derived binaries are covered by the terms and
* conditions of the Licence agreement ("the Licence"). You may not use this
* source code or any derived binaries except in compliance with the Licence.
* A copy of the Licence is available in the file named LICENCE shipped with
* this source code or binaries.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* Licence for the specific language governing permissions and limitations
* under the Licence.
*/
import static org.junit.Assert.*;
import static org.mockito.MockitoAnnotations.*;

import java.util.StringTokenizer;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

import synapticloop.templar.Parser;
import synapticloop.templar.exception.ParseException;
import synapticloop.templar.utils.Tokeniser;

public class StaticTokenTest {
@Mock StringTokenizer mockStringTokenizer;
@Mock Tokeniser mockTokeniser;

@Before
public void setup() {
initMocks(this);
}

@Test(expected = ParseException.class)
public void testParse() throws ParseException{
Parser parser = new Parser("{static ./StaticTokenTest.java}");
assertEquals("<STATIC@1:2 (./StaticTokenTest.java) />", parser.toString());
}

}

0 comments on commit e91bccc

Please sign in to comment.