Skip to content

Commit

Permalink
increased test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperjj committed Aug 4, 2016
1 parent 2147a79 commit 54384e5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/main/java/me/doubledutch/lazyjson/LazyToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ protected static LazyToken cValueNull(int index){
* @throws LazyException if the value could not be parsed
*/
protected int getIntValue(char[] source) throws LazyException{
if(type!=VALUE_NUMBER || modified)throw new LazyException("Not an integer",startIndex);
int i=startIndex;
boolean sign=false;
if(source[i]=='-'){
Expand All @@ -192,7 +193,8 @@ protected int getIntValue(char[] source) throws LazyException{
int value=0;
for(;i<endIndex;i++){
char c=source[i];
if(c<'0'||c>'9')throw new LazyException("'"+getStringValue(source)+"' is not a valid integer",startIndex);
// If we only allow this to be called on integer values, the parsing is pre done!
// if(c<'0'||c>'9')throw new LazyException("'"+getStringValue(source)+"' is not a valid integer",startIndex);
value+='0'-c;
if(i+1<endIndex){
value*=10;
Expand All @@ -210,6 +212,7 @@ protected int getIntValue(char[] source) throws LazyException{
* @throws LazyException if the value could not be parsed
*/
protected long getLongValue(char[] source) throws LazyException{
if(type!=VALUE_NUMBER || modified)throw new LazyException("Not a long",startIndex);
int i=startIndex;
boolean sign=false;
if(source[i]=='-'){
Expand All @@ -219,7 +222,6 @@ protected long getLongValue(char[] source) throws LazyException{
long value=0;
for(;i<endIndex;i++){
char c=source[i];
if(c<'0'||c>'9')throw new LazyException("'"+getStringValue(source)+"' is not a valid integer",startIndex);
value+='0'-c;
if(i+1<endIndex){
value*=10;
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/version.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Thu Aug 04 13:44:24 PDT 2016
#Thu Aug 04 13:57:17 PDT 2016
BUILD_VERSION=1.1.0
BUILD_DATE=2016-08-04T20\:44\:24Z
BUILD_NUMBER=221
BUILD_DATE=2016-08-04T20\:57\:17Z
BUILD_NUMBER=235
7 changes: 7 additions & 0 deletions src/test/java/me/doubledutch/lazyjson/LazyArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public void testLength() throws LazyException{
assertEquals(3,array.length());
}

@Test
public void testEmptyLength() throws LazyException{
String str="[]";
LazyArray array=new LazyArray(str);
assertEquals(0,array.length());
}

@Test
public void testNullValues() throws LazyException{
String str="[false,null,true]";
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/me/doubledutch/lazyjson/LazyObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,15 @@ public void testLength() throws LazyException{

@Test
public void testStringFields() throws LazyException{
String str="{\"foo\":\"bar\",\"baz\":\"\"}";
String str="{\"foo\":\"bar\",\"baz\":\"\",\"bonk\":\"\\t\\b\\r\\n\\\\\\\"\\f\"}";
LazyObject obj=new LazyObject(str);
String value=obj.getString("foo");
assertNotNull(value);
assertEquals(value,"bar");
value=obj.getString("baz");
assertNotNull(value);
assertEquals(value,"");
assertEquals(obj.getString("bonk"),"\t\b\r\n\\\"\f");
}

@Test
Expand Down

0 comments on commit 54384e5

Please sign in to comment.