mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
couple more tests to community
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
package com.intellij.lexer;
|
||||
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class LayeredLexerTest extends TestCase {
|
||||
public void testInTheMiddle() throws Exception {
|
||||
Lexer lexer = setupLexer("s=\"abc\\ndef\";");
|
||||
|
||||
assertEquals("s", nextToken(lexer));
|
||||
assertEquals("=", nextToken(lexer));
|
||||
assertEquals("\"abc", nextToken(lexer));
|
||||
assertEquals("\\n", nextToken(lexer));
|
||||
assertEquals("def\"", nextToken(lexer));
|
||||
assertEquals(";", nextToken(lexer));
|
||||
assertEquals(null, lexer.getTokenType());
|
||||
}
|
||||
|
||||
public void testModification() throws Exception {
|
||||
Lexer lexer = setupLexer("s=\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\";");
|
||||
assertEquals("s", nextToken(lexer));
|
||||
assertEquals("=", nextToken(lexer));
|
||||
assertEquals("\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"", nextToken(lexer));
|
||||
assertEquals(";", nextToken(lexer));
|
||||
assertEquals(null, lexer.getTokenType());
|
||||
|
||||
lexer.start(lexer.getBufferSequence(), 2, lexer.getBufferEnd(), (short) 1);
|
||||
assertEquals("\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"", nextToken(lexer));
|
||||
assertEquals(";", nextToken(lexer));
|
||||
assertEquals(null, lexer.getTokenType());
|
||||
}
|
||||
|
||||
|
||||
public void testInTheAtStartup() throws Exception {
|
||||
Lexer lexer = setupLexer("s=\"\\ndef\";");
|
||||
|
||||
assertEquals("s", nextToken(lexer));
|
||||
assertEquals("=", nextToken(lexer));
|
||||
assertEquals("\"", nextToken(lexer));
|
||||
assertEquals("\\n", nextToken(lexer));
|
||||
assertEquals("def\"", nextToken(lexer));
|
||||
assertEquals(";", nextToken(lexer));
|
||||
assertEquals(null, lexer.getTokenType());
|
||||
}
|
||||
|
||||
public void testInTheAtEnd() throws Exception {
|
||||
Lexer lexer = setupLexer("s=\"abc\\n\";");
|
||||
|
||||
assertEquals("s", nextToken(lexer));
|
||||
assertEquals("=", nextToken(lexer));
|
||||
assertEquals("\"abc", nextToken(lexer));
|
||||
assertEquals("\\n", nextToken(lexer));
|
||||
assertEquals("\"", nextToken(lexer));
|
||||
assertEquals(";", nextToken(lexer));
|
||||
assertEquals(null, lexer.getTokenType());
|
||||
}
|
||||
|
||||
public void testNonTerminated() throws Exception {
|
||||
Lexer lexer = setupLexer("s=\"abc\\n");
|
||||
|
||||
assertEquals("s", nextToken(lexer));
|
||||
assertEquals("=", nextToken(lexer));
|
||||
assertEquals("\"abc", nextToken(lexer));
|
||||
assertEquals("\\n", nextToken(lexer));
|
||||
assertEquals(null, lexer.getTokenType());
|
||||
}
|
||||
|
||||
public void testNonTerminated2() throws Exception {
|
||||
Lexer lexer = setupLexer("s=\"abc\\");
|
||||
|
||||
assertEquals("s", nextToken(lexer));
|
||||
assertEquals("=", nextToken(lexer));
|
||||
assertEquals("\"abc", nextToken(lexer));
|
||||
assertEquals("\\", nextToken(lexer));
|
||||
assertEquals(null, lexer.getTokenType());
|
||||
}
|
||||
|
||||
public void testUnicode() throws Exception {
|
||||
Lexer lexer = setupLexer("s=\"\\uFFFF\";");
|
||||
assertEquals("s", nextToken(lexer));
|
||||
assertEquals("=", nextToken(lexer));
|
||||
assertEquals("\"", nextToken(lexer));
|
||||
assertEquals("\\uFFFF", nextToken(lexer));
|
||||
assertEquals("\"", nextToken(lexer));
|
||||
assertEquals(";", nextToken(lexer));
|
||||
assertEquals(null, lexer.getTokenType());
|
||||
}
|
||||
|
||||
private Lexer setupLexer(String text) {
|
||||
LayeredLexer lexer = new LayeredLexer(new JavaLexer(LanguageLevel.JDK_1_3));
|
||||
lexer.registerSelfStoppingLayer(new StringLiteralLexer('\"', JavaTokenType.STRING_LITERAL),
|
||||
new IElementType[]{JavaTokenType.STRING_LITERAL},
|
||||
IElementType.EMPTY_ARRAY);
|
||||
|
||||
lexer.start(text);
|
||||
return lexer;
|
||||
}
|
||||
|
||||
private String nextToken(Lexer lexer) {
|
||||
assertTrue(lexer.getTokenType() != null);
|
||||
final String s = lexer.getBufferSequence().subSequence(lexer.getTokenStart(), lexer.getTokenEnd()).toString();
|
||||
lexer.advance();
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
package com.intellij.diff;
|
||||
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.diff.FilesTooBigForDiffException;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* author: lesya
|
||||
*/
|
||||
|
||||
public class SelectedBlockHistoryTest extends TestCase {
|
||||
|
||||
public void test1() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"},
|
||||
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "52", "6"},
|
||||
new String[]{"7", "8", "9"}
|
||||
);
|
||||
}
|
||||
|
||||
public void test2() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{"1", "1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"},
|
||||
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "52", "6"},
|
||||
new String[]{"7", "8", "9"}
|
||||
);
|
||||
}
|
||||
|
||||
public void test3() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"},
|
||||
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"}
|
||||
);
|
||||
}
|
||||
|
||||
public void test4() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"},
|
||||
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"}
|
||||
);
|
||||
}
|
||||
|
||||
public void test5() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{},
|
||||
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"}
|
||||
);
|
||||
}
|
||||
|
||||
public void test6() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"},
|
||||
|
||||
new String[]{},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"}
|
||||
);
|
||||
}
|
||||
|
||||
public void test7() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"},
|
||||
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{}
|
||||
);
|
||||
}
|
||||
|
||||
public void test8() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"},
|
||||
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"44", "4", "5", "6", "66"},
|
||||
new String[]{"7", "8", "9"}
|
||||
);
|
||||
}
|
||||
|
||||
public void test9() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"},
|
||||
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"44", "4", "55", "6", "66"},
|
||||
new String[]{"7", "8", "9"}
|
||||
);
|
||||
}
|
||||
|
||||
public void test10() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{"0.5", "1", "3", "3.5"},
|
||||
new String[]{"4", "5","5.5", "6"},
|
||||
new String[]{"6,5", "7", "8", "9", "9.5"},
|
||||
|
||||
new String[]{"+0.5", "1", "2", "3", "3.5+", "3.5++"},
|
||||
new String[]{"4", "5","5.5+", "6"},
|
||||
new String[]{"+6,5","++6,5", "7", "9", "9.5+", "9.5++"}
|
||||
);
|
||||
}
|
||||
|
||||
public void test11() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"a", "a"},
|
||||
new String[]{"7", "8", "9"},
|
||||
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"b"},
|
||||
new String[]{"7", "8", "9"}
|
||||
);
|
||||
}
|
||||
|
||||
public void test12() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{},
|
||||
new String[]{"7", "8", "9"},
|
||||
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"}
|
||||
);
|
||||
}
|
||||
|
||||
public void test13() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"},
|
||||
|
||||
new String[]{},
|
||||
new String[]{"4", "52", "6"},
|
||||
new String[]{}
|
||||
);
|
||||
}
|
||||
|
||||
public void test14() throws FilesTooBigForDiffException {
|
||||
doTest(
|
||||
new String[]{},
|
||||
new String[]{"4", "52", "6"},
|
||||
new String[]{},
|
||||
|
||||
new String[]{"1", "2", "3"},
|
||||
new String[]{"4", "5", "6"},
|
||||
new String[]{"7", "8", "9"}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public void testContent(){
|
||||
Block block = new Block("0\n1\n2\n3\n4\n5\n6", 3, 6);
|
||||
String blockContent = block.getBlockContent();
|
||||
assertEquals("3\n4\n5\n6", blockContent);
|
||||
|
||||
block = new Block("0\n1\n2\n3\n4\n5\n6\n", 3, 6);
|
||||
blockContent = block.getBlockContent();
|
||||
assertEquals("3\n4\n5\n6", blockContent);
|
||||
|
||||
}
|
||||
|
||||
private void doTest(
|
||||
String[] beforePrevBlock,
|
||||
String[] prevBlock,
|
||||
String[] afterPrevBlock,
|
||||
String[] beforeBlock,
|
||||
String[] block,
|
||||
String[] afterBlock) throws FilesTooBigForDiffException {
|
||||
|
||||
String[] prevVersion = composeVersion(beforePrevBlock, prevBlock, afterPrevBlock);
|
||||
String[] currentVersion = composeVersion(beforeBlock, block, afterBlock);
|
||||
FindBlock findBlock = new FindBlock(prevVersion,
|
||||
new Block(currentVersion, beforeBlock.length, beforeBlock.length + block.length - 1));
|
||||
|
||||
Block actualBlock = findBlock.getBlockInThePrevVersion();
|
||||
Block expectedBlock = new Block(prevVersion,beforePrevBlock.length, beforePrevBlock.length + prevBlock.length - 1);
|
||||
|
||||
assertEquals(expectedBlock, actualBlock);
|
||||
|
||||
}
|
||||
|
||||
private String[] composeVersion(String[] beforeBlock, String[] block, String[] afterBlock) {
|
||||
List beforeList = new ArrayList();
|
||||
ContainerUtil.addAll(beforeList, beforeBlock);
|
||||
ContainerUtil.addAll(beforeList, block);
|
||||
ContainerUtil.addAll(beforeList, afterBlock);
|
||||
return (String[])ArrayUtil.toStringArray(beforeList);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user