| /******************************************************************************* |
| * Copyright (c) 2000, 2007 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.wst.jsdt.core.tests.compiler.regression; |
| |
| import junit.framework.Test; |
| |
| import org.eclipse.wst.jsdt.core.compiler.InvalidInputException; |
| import org.eclipse.wst.jsdt.internal.compiler.parser.Scanner; |
| import org.eclipse.wst.jsdt.internal.compiler.parser.TerminalTokens; |
| public class InternalScannerTest extends AbstractRegressionTest { |
| |
| public InternalScannerTest(String name) { |
| super(name); |
| } |
| |
| public static Class testClass() { |
| return InternalScannerTest.class; |
| } |
| |
| /** |
| * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23181 |
| */ |
| public void test001() { |
| String source = "//Comment"; |
| Scanner scanner = new Scanner(); |
| scanner.setSource(source.toCharArray()); |
| int token = 0; |
| try { |
| token = scanner.getNextToken(); |
| } catch (InvalidInputException e) { |
| // ignore |
| } |
| assertEquals("Wrong token type", TerminalTokens.TokenNameEOF, token); |
| assertEquals("Wrong comment start", 0, scanner.commentStarts[0]); |
| assertEquals("Wrong comment start", -9, scanner.commentStops[0]); |
| } |
| |
| /** |
| * http://bugs.eclipse.org/bugs/show_bug.cgi?id=73762 |
| */ |
| public void test002() throws InvalidInputException { |
| Scanner scanner = new Scanner(); |
| scanner.recordLineSeparator = true; |
| scanner.setSource("a\nb\nc\n".toCharArray()); |
| int token = 0; |
| while (token != TerminalTokens.TokenNameEOF) { |
| token = scanner.getNextToken(); |
| } |
| scanner.setSource("a\nb\n".toCharArray()); |
| token = 0; |
| while (token != TerminalTokens.TokenNameEOF) { |
| token = scanner.getNextToken(); |
| } |
| assertEquals("Wrong number of line ends", 2, scanner.getLineEnds().length); |
| } |
| |
| } |