tools/JavaParserITests.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 06 Sep 2013 00:16:38 +0100
branchdevelopment
changeset 2711 a00302fe5083
parent 2482 109ed9ecf4f7
child 2731 13f5be2bf83b
permissions -rw-r--r--
Added version_CVS to all classes and build files regenerated & cleaned. This is necessary step before updating CVS.

"{ Package: 'stx:libjava/tools' }"

PPCompositeParserTest subclass:#JavaParserITests
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Java-Tests-Parser'
!


!JavaParserITests methodsFor:'accessing'!

parserClass
        ^ JavaParserI

    "Modified: / 09-03-2012 / 23:27:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaParserITests methodsFor:'parsing'!

fail: aString rule: aSymbol 

    ^super fail: (JavaScanner for: aString) rule: aSymbol

    "Created: / 14-03-2012 / 22:51:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

parse: aString rule: aSymbol 

    ^super parse: (JavaScanner for: aString) rule: aSymbol

    "Created: / 14-03-2012 / 22:51:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaParserITests methodsFor:'testing'!

testIdentifier6

	self
		fail: 'super'
		rule: #identifier
!

testIdentifier7

	self
		fail: 'super'
		rule: #identifier
! !

!JavaParserITests methodsFor:'testing-identifiers'!

testIdentifier                                             
!

testIdentifier1

	self
		parse: 'String'
		rule: #identifier
!

testIdentifier1b

        self
                parse: '/*comment before*/ String'
                rule: #identifier

    "Created: / 14-03-2012 / 23:16:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testIdentifier2

	self
		parse: 'i3'
		rule: #identifier
!

testIdentifier4

	self
		parse: 'MAX_VALUE'
		rule: #identifier
!

testIdentifier5

	self
		parse: 'isLetterOrDigit'
		rule: #identifier
! !

!JavaParserITests methodsFor:'testing-input'!

testInput1

	self parse: 'package testPackage;
						class Test {
        				public static void main(String[] args) {
                			String hello = "Hello", lo = "lo";
                			System.out.print((hello == "Hello") + " ");
                			System.out.print((Other.hello == hello) + " ");
                			System.out.print((other.Other.hello == hello) + " ");
                			System.out.print((hello == ("Hel"+"lo")) + " ");
                			System.out.print((hello == ("Hel"+lo)) + " ");
                			System.out.println(hello == ("Hel"+lo).intern());
        				}
						}
						class Other { static String hello = "Hello"; }'
	rule: #input
!

testInput2

	self parse: 'package other;
						public class Other { static String hello = "Hello"; }'
	rule: #input
!

testInput3

	self parse: 'class Value { int val; }	
						class Test {
        				public static void main(String[] args) {
              			int i1 = 3;
                		int i2 = i1;
                		i2 = 4;
                		System.out.print("i1==" + i1);
                		System.out.println(" but i2==" + i2);
                		Value v1 = new Value();
                		v1.val = 5;
                		Value v2 = v1;
                		v2.val = 6;
                		System.out.print("v1.val==" + v1.val);
                		System.out.println(" and v2.val==" + v2.val);
        				}
						}'
	rule: #input
! !

!JavaParserITests methodsFor:'testing-lineTerminators'!

testInputCharacter1

	self
		parse: '\'
		rule: #inputCharacter
!

testInputCharacter2

	self
		fail: (Character cr asString)
		rule: #inputCharacter
!

testInputCharacter3

	self
		fail: (Character lf asString)
		rule: #inputCharacter
!

testLineTerminator1

	self
		parse: (Character lf asString)
		rule: #lineTerminator
!

testLineTerminator2

	self
		parse: (Character cr asString)
		rule: #lineTerminator
!

testLineTerminator3

	self
		parse: (Character cr asString , Character lf asString)
		rule: #lineTerminator
!

testLineTerminator4

	self
		fail: (Character space asString)
		rule: #lineTerminator
! !

!JavaParserITests methodsFor:'testing-literal-float'!

testFloatLiteral1
	self 
		parse: '1e1f'
		rule: #floatingPointLiteral
!

testFloatLiteral10
	self 
		parse: '0.0'
		rule: #floatingPointLiteral
!

testFloatLiteral11
	self 
		parse: '3.14'
		rule: #floatingPointLiteral
!

testFloatLiteral12
	self 
		parse: '1e-9d'
		rule: #floatingPointLiteral
!

testFloatLiteral13
	self 
		parse: '1e137'
		rule: #floatingPointLiteral
!

testFloatLiteral2
	self 
		parse: '2.f'
		rule: #floatingPointLiteral
!

testFloatLiteral3
	self 
		parse: '.3f'
		rule: #floatingPointLiteral
!

testFloatLiteral4
	self 
		parse: '0f'
		rule: #floatingPointLiteral
!

testFloatLiteral5
	self 
		parse: '3.14f'
		rule: #floatingPointLiteral
!

testFloatLiteral6
	self 
		parse: '6.022137e+23f'
		rule: #floatingPointLiteral
!

testFloatLiteral7
	self 
		parse: '1e1'
		rule: #floatingPointLiteral
!

testFloatLiteral8
	self 
		parse: '2.'
		rule: #floatingPointLiteral
!

testFloatLiteral9
	self 
		parse: '.3'
		rule: #floatingPointLiteral
! !

!JavaParserITests methodsFor:'testing-literals'!

testBooleanLiteral1
	self 
		parse: 'true'
		rule: #booleanLiteral
!

testBooleanLiteral2
	self 
		parse: 'false'
		rule: #booleanLiteral
!

testLiteral1

	self 
		parse: 'null'
		rule: #literal
!

testLiteral10

	self 
		fail: '0777 L'
		rule: #literal
!

testLiteral11

	self 
		fail: '0777 0'
		rule: #literal
!

testLiteral12

	self 
		fail: '0 x'
		rule: #literal
!

testLiteral2

	self 
		parse: 'false'
		rule: #literal
!

testLiteral3

	self 
		parse: '6.022137e+23f'
		rule: #literal
!

testLiteral4

	self 
		parse: '1e1'
		rule: #literal
!

testLiteral5

	self 
		parse: '0x100000000L'
		rule: #literal
!

testLiteral6

	self 
		parse: '0372'
		rule: #literal
!

testLiteral7

	self 
		parse: '0xDadaCafe'
		rule: #literal
!

testLiteral8

	self 
		parse: '0x00FF00FF'
		rule: #literal
!

testLiteral9

	self 
		parse: '0777L'
		rule: #literal
!

testNullLiteral1

	self 
		parse: 'null'
		rule: #nullLiteral
!

testStringLiteral1

	self 
		parse: '""'
		rule: #stringLiteral
!

testStringLiteral10

        self 
                parse: '"This is a \\
                                two lines Java string"'
                rule: #stringLiteral

    "Modified: / 14-03-2012 / 23:54:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testStringLiteral11

	self 
		parse: '"null"'
		rule: #stringLiteral
!

testStringLiteral2

	self 
		parse: '"\""'
		rule: #stringLiteral
!

testStringLiteral3

	self 
		parse: '"This is a Java string"'
		rule: #stringLiteral
!

testStringLiteral4

        self 
                parse: '"This is a 
                                two lines Java string"'
                rule: #stringLiteral

    "Modified: / 14-03-2012 / 23:54:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testStringLiteral5

        self 
                parse: '"This is a \b
                                two lines Java string"'
                rule: #stringLiteral

    "Modified: / 14-03-2012 / 23:54:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testStringLiteral6

        self 
                parse: '"This is a \t
                                two lines Java string"'
                rule: #stringLiteral

    "Modified: / 14-03-2012 / 23:55:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testStringLiteral7

        self 
                parse: '"This is a \n
                                two lines Java string"'
                rule: #stringLiteral

    "Modified: / 14-03-2012 / 23:55:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testStringLiteral8

        self 
                parse: '"This is a \f
                                two lines Java string"'
                rule: #stringLiteral

    "Modified: / 14-03-2012 / 23:55:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testStringLiteral9

        self 
                parse: '"This is a \r
                                two lines Java string"'
                rule: #stringLiteral

    "Modified: / 14-03-2012 / 23:55:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaParserITests methodsFor:'testing-literals-characters'!

testCharacterLiteral1
	self 
		parse: '''a'''
		rule: #characterLiteral
!

testCharacterLiteral2
	self 
		parse: '''%'''
		rule: #characterLiteral
!

testCharacterLiteral3
	self 
		parse: '''\t'''
		rule: #characterLiteral
!

testCharacterLiteral4
	self 
		parse: '''\\'''
		rule: #characterLiteral
!

testCharacterLiteral5
	self 
		parse: '''\'''''
		rule: #characterLiteral
!

testCharacterLiteral6
        "not clear how this must be supported
        (see http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.6)"
        
        self 
                parse: '''\u03a9'''
                rule: #characterLiteral

    "Modified: / 15-03-2012 / 22:52:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testCharacterLiteral7
        "not clear how this must be supported
        (see http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.6)"
        
        self 
                parse: '''\uFFFF'''
                rule: #characterLiteral

    "Modified: / 15-03-2012 / 22:53:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testCharacterLiteral8
	self 
		parse: '''\177'''
		rule: #characterLiteral
!

testCharacterLiteral9
	self 
		parse: '''\177'''
		rule: #characterLiteral
! !

!JavaParserITests methodsFor:'testing-literals-integer'!

testHexIntegerLiteral1
        self 
                parse: '0xC0B0L'
                rule: #integerLiteral

    "Modified: / 15-03-2012 / 00:09:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testIntegerLiteral1
        self 
                parse: '0 '
                rule: #integerLiteral

    "Modified: / 15-03-2012 / 08:37:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

testIntegerLiteral10
	self 
		parse: '1996'
		rule: #integerLiteral
!

testIntegerLiteral11
	self 
		parse: '0x00FF00FF'
		rule: #integerLiteral
!

testIntegerLiteral2
	self 
		parse: '0l'
		rule: #integerLiteral
!

testIntegerLiteral3
	self 
		parse: '0777L'
		rule: #integerLiteral
!

testIntegerLiteral4
	self 
		parse: '0x100000000L'
		rule: #integerLiteral
!

testIntegerLiteral5
	self 
		parse: '2147483648L'
		rule: #integerLiteral
!

testIntegerLiteral6
	self 
		parse: '0xC0B0L'
		rule: #integerLiteral
!

testIntegerLiteral7
	self 
		parse: '2'
		rule: #integerLiteral
!

testIntegerLiteral8
	self 
		parse: '0372'
		rule: #integerLiteral
!

testIntegerLiteral9
	self 
		parse: '0xDadaCafe'
		rule: #integerLiteral
!

testOctalIntegerLiteral1
        self 
                parse: '0777L'
                rule: #integerLiteral

    "Modified: / 15-03-2012 / 08:40:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaParserITests methodsFor:'testing-unicode'!

testUnicodeEscape1

	self
		parse: '\u0000'
		rule: #unicodeEscape
!

testUnicodeEscape2

	self
		fail: '\u000'
		rule: #unicodeEscape
!

testUnicodeEscape3

	self
		fail: '\u00000'
		rule: #unicodeEscape
!

testUnicodeInputCharacter1

	self
		parse: '\u0000'
		rule: #unicodeInputCharacter
!

testUnicodeInputCharacter2

	self
		parse: '\'
		rule: #unicodeInputCharacter
!

testUnicodeInputCharacter3

	self
		parse: 'µ'
		rule: #unicodeInputCharacter
!

testUnicodeInputCharacter4

	self
		fail: '\\'
		rule: #unicodeInputCharacter
! !

!JavaParserITests class methodsFor:'documentation'!

version_CVS
    ^ '$Header$'
!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '§Id§'
! !