Created
July 5, 2012 16:08
-
-
Save banshee/3054567 to your computer and use it in GitHub Desktop.
Tests for the Java signature parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.restphone.parser.test | |
import org.scalatest.matchers.ShouldMatchers | |
import org.scalatest.Spec | |
import org.scalatest.FunSuite | |
import scala.collection.mutable.Stack | |
import com.google.common.collect._ | |
import com.google.common.collect.Ranges | |
import org.junit.runner.RunWith | |
import org.scalatest.junit.JUnitRunner | |
import com.restphone.parser._ | |
import com.restphone.parser.JavaSignatureParser | |
@RunWith( classOf[ JUnitRunner ] ) | |
class JavaSignatureParserTest extends FunSuite { | |
val p = new JavaSignatureParser | |
test( "can parse a Java primitive" ) { | |
expect( "boolean" ) { | |
p.parseAll( p.typeSignature, "Z" ).get.toJava | |
} | |
} | |
test( "java.util.List<E>" ) { | |
expect( "java.util.List<E>" ) { | |
p.parseAll( p.typeSignature, "Ljava/util/List<TE;>;" ).get.toJava | |
} | |
} | |
test( "Number" ) { | |
expect( "Number" ) { | |
val result = p.parseAll( p.typeArg, "Ljava/lang/Number;" ) | |
result.get.toJava | |
} | |
} | |
test( "List<Number>" ) { | |
expect( "java.util.List<Number>" ) { | |
val result = p.parseAll( p.typeSignature, "Ljava/util/List<Ljava/lang/Number;>;" ) | |
result.get.toJava | |
} | |
} | |
test( "java.util.List<? extends Number>" ) { | |
expect( "java.util.List<? extends Number>" ) { | |
val result = p.parseAll( p.typeSignature, "Ljava/util/List<+Ljava/lang/Number;>;" ) | |
result.get.toJava | |
} | |
} | |
test( "java.util.List<? super Number>" ) { | |
expect( "java.util.List<? super Number>" ) { | |
val result = p.parseAll( p.typeSignature, "Ljava/util/List<-Ljava/lang/Number;>;" ) | |
result.get.toJava | |
} | |
} | |
test( "List<List<String>[]>" ) { | |
expect( "java.util.List<java.util.List<String>[]>" ) { | |
val result = p.parseAll( p.typeSignature, "Ljava/util/List<[Ljava/util/List<Ljava/lang/String;>;>;" ) | |
result.get.toJava | |
} | |
} | |
test( "HashMap<K, V>.HashIterator<K>" ) { | |
expect( "java.util.HashMap<K, V>.HashIterator<K, V>" ) { | |
val result = p.parseAll( p.typeSignature, "Ljava/util/HashMap<TK;TV;>.HashIterator<TK;TV;>;" ) | |
result.get.toJava | |
} | |
} | |
test( "java.util.List<?>" ) { | |
expect( "java.util.List<?>" ) { | |
val result = p.parseAll( p.typeSignature, "Ljava/util/List<*>;" ) | |
result.get.toJava | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment