/*******************************************************************************
 * Copyright (c) 2008 itemis AG (http://www.itemis.eu) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 *******************************************************************************/
package org.eclipse.xtext.lexer;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CommonToken;
import org.antlr.runtime.CommonTokenStream;
import org.eclipse.xtext.testlanguages.parser.internal.InternalSimpleExpressionsLexer;

import junit.framework.TestCase;

/**
 * @author Dennis Hbner - Initial contribution and API
 * 
 */
public class LexerSLComment extends TestCase {
	public void testSlComment() {
		String model = "//sl comment\na";
		InternalSimpleExpressionsLexer lexer = new InternalSimpleExpressionsLexer();
		lexer.setCharStream(new ANTLRStringStream(model));
		CommonTokenStream stream = new CommonTokenStream(lexer);
		Object inLineComment = stream.getTokens().get(0);
		assertTrue(inLineComment instanceof CommonToken);
		assertEquals(InternalSimpleExpressionsLexer.RULE_SL_COMMENT, ((CommonToken) inLineComment).getType());
	}

	/**
	 * see BUG 234135: Comments on EOF not detected
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=234135
	 */
	public void testSlCommentEOF() {
		String model = "a\n//sl comment";
		InternalSimpleExpressionsLexer lexer = new InternalSimpleExpressionsLexer();
		lexer.setCharStream(new ANTLRStringStream(model));
		CommonTokenStream stream = new CommonTokenStream(lexer);
		Object eofLineComment = stream.getTokens().get(2);
		assertTrue(eofLineComment instanceof CommonToken);
		assertEquals(InternalSimpleExpressionsLexer.RULE_SL_COMMENT, ((CommonToken) eofLineComment).getType());
	}
}

FIX for BUG 234135: Comments on EOF not detected https://bugs.eclipse.org/bugs/show_bug.cgi?id=234135