| /******************************************************************************* |
| * Copyright (c) 2000, 2003 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Common Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.jdt.core.tests.compiler.regression; |
| |
| import junit.framework.Test; |
| |
| import org.eclipse.jdt.core.ToolFactory; |
| import org.eclipse.jdt.core.compiler.IScanner; |
| import org.eclipse.jdt.core.compiler.ITerminalSymbols; |
| import org.eclipse.jdt.core.compiler.InvalidInputException; |
| public class ScannerTest extends AbstractRegressionTest { |
| |
| public ScannerTest(String name) { |
| super(name); |
| } |
| public static Test suite() { |
| return setupSuite(testClass()); |
| } |
| |
| public static Class testClass() { |
| return ScannerTest.class; |
| } |
| |
| /** |
| * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23181 |
| */ |
| public void test001() { |
| String sourceA001 = "\\u003b"; |
| IScanner scanner = ToolFactory.createScanner(false, true, false, false); |
| scanner.setSource(sourceA001.toCharArray()); |
| int token = 0; |
| try { |
| token = scanner.getNextToken(); |
| } catch (InvalidInputException e) { |
| } |
| assertEquals("Wrong token type", ITerminalSymbols.TokenNameSEMICOLON, token); |
| } |
| /** |
| * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23181 |
| */ |
| public void test002() { |
| String sourceA002 = "// tests\n "; |
| IScanner scanner = ToolFactory.createScanner(false, true, false, false); |
| scanner.setSource(sourceA002.toCharArray()); |
| int token = 0; |
| try { |
| token = scanner.getNextToken(); |
| assertEquals("Wrong token type", ITerminalSymbols.TokenNameWHITESPACE, token); |
| assertEquals("Wrong size", 2, scanner.getCurrentTokenSource().length); |
| token = scanner.getNextToken(); |
| assertEquals("Wrong token type", ITerminalSymbols.TokenNameEOF, token); |
| } catch (InvalidInputException e) { |
| } |
| } |
| /** |
| * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23181 |
| */ |
| public void test003() { |
| String sourceA003 = "// tests\n "; |
| IScanner scanner = ToolFactory.createScanner(true, true, false, false); |
| scanner.setSource(sourceA003.toCharArray()); |
| int token = 0; |
| try { |
| token = scanner.getNextToken(); |
| assertEquals("Wrong token type", ITerminalSymbols.TokenNameCOMMENT_LINE, token); |
| token = scanner.getNextToken(); |
| assertEquals("Wrong token type", ITerminalSymbols.TokenNameWHITESPACE, token); |
| assertEquals("Wrong size", 2, scanner.getCurrentTokenSource().length); |
| token = scanner.getNextToken(); |
| assertEquals("Wrong token type", ITerminalSymbols.TokenNameEOF, token); |
| } catch (InvalidInputException e) { |
| } |
| } |
| |
| /** |
| * float constant can have exponent part without dot: 01e0f |
| * http://bugs.eclipse.org/bugs/show_bug.cgi?id=30704 |
| */ |
| public void test004() { |
| String source = "01e0f"; |
| IScanner scanner = ToolFactory.createScanner(false, false, false, false); |
| scanner.setSource(source.toCharArray()); |
| int token = 0; |
| try { |
| token = scanner.getNextToken(); |
| assertEquals("Wrong token type", ITerminalSymbols.TokenNameFloatingPointLiteral, token); |
| } catch (InvalidInputException e) { |
| } |
| } |
| |
| } |