File: YylexTest.java

package info (click to toggle)
json-simple 1.1-dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 228 kB
  • sloc: java: 1,810; xml: 69; makefile: 16; sh: 11
file content (80 lines) | stat: -rw-r--r-- 2,039 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package org.json.simple.parser;

import java.io.IOException;
import java.io.StringReader;

import junit.framework.TestCase;

public class YylexTest extends TestCase {

	public void testYylex() throws Exception{
		String s="\"\\/\"";
		System.out.println(s);
		StringReader in = new StringReader(s);
		Yylex lexer=new Yylex(in);
		Yytoken token=lexer.yylex();
		assertEquals(Yytoken.TYPE_VALUE,token.type);
		assertEquals("/",token.value);
		
		s="\"abc\\/\\r\\b\\n\\t\\f\\\\\"";
		System.out.println(s);
		in = new StringReader(s);
		lexer=new Yylex(in);
		token=lexer.yylex();
		assertEquals(Yytoken.TYPE_VALUE,token.type);
		assertEquals("abc/\r\b\n\t\f\\",token.value);
		
		s="[\t \n\r\n{ \t \t\n\r}";
		System.out.println(s);
		in = new StringReader(s);
		lexer=new Yylex(in);
		token=lexer.yylex();
		assertEquals(Yytoken.TYPE_LEFT_SQUARE,token.type);
		token=lexer.yylex();
		assertEquals(Yytoken.TYPE_LEFT_BRACE,token.type);
		token=lexer.yylex();
		assertEquals(Yytoken.TYPE_RIGHT_BRACE,token.type);
		
		s="\b\f{";
		System.out.println(s);
		in = new StringReader(s);
		lexer=new Yylex(in);
		ParseException err=null;
		try{
			token=lexer.yylex();
		}
		catch(ParseException e){
			err=e;
			System.out.println("error:"+err);
			assertEquals(ParseException.ERROR_UNEXPECTED_CHAR, e.getErrorType());
			assertEquals(0,e.getPosition());
			assertEquals(new Character('\b'),e.getUnexpectedObject());
		}
		catch(IOException ie){
			throw ie;
		}
		assertTrue(err!=null);
		
		s="{a : b}";
		System.out.println(s);
		in = new StringReader(s);
		lexer=new Yylex(in);
		err=null;
		try{
			lexer.yylex();
			token=lexer.yylex();
		}
		catch(ParseException e){
			err=e;
			System.out.println("error:"+err);
			assertEquals(ParseException.ERROR_UNEXPECTED_CHAR, e.getErrorType());
			assertEquals(new Character('a'),e.getUnexpectedObject());
			assertEquals(1,e.getPosition());
		}
		catch(IOException ie){
			throw ie;
		}
		assertTrue(err!=null);
	}

}