use of com.ichi2.libanki.importer.TextImporter in project AnkiChinaAndroid by ankichinateam.
the class ImportTest method testCsv.
@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testCsv() throws IOException {
String file = Shared.getTestFilePath(InstrumentationRegistry.getInstrumentation().getTargetContext(), "text-2fields.txt");
TextImporter i = new TextImporter(testCol, file);
i.initMapping();
i.run();
if (TestEnvironment.isDisplayingDefaultEnglishStrings()) {
assertThat(i.getLog(), contains("‘多すぎる too many fields’ had 3 fields, expected 2", "‘not, enough, fields’ had 1 fields, expected 2", "Appeared twice in file: 飲む", "Empty first field: to play", "5 notes added, 0 notes updated, 0 notes unchanged."));
} else {
assertThat(i.getLog(), hasSize(5));
}
assertEquals(5, i.getTotal());
// if we run the import again, it should update instead
i.run();
if (TestEnvironment.isDisplayingDefaultEnglishStrings()) {
assertThat(i.getLog(), contains("‘多すぎる too many fields’ had 3 fields, expected 2", "‘not, enough, fields’ had 1 fields, expected 2", "Appeared twice in file: 飲む", "Empty first field: to play", "0 notes added, 0 notes updated, 5 notes unchanged.", "First field matched: 食べる", "First field matched: 飲む", "First field matched: テスト", "First field matched: to eat", "First field matched: 遊ぶ"));
} else {
assertThat(i.getLog(), hasSize(10));
}
assertEquals(5, i.getTotal());
// but importing should not clobber tags if they're unmapped
Note n = testCol.getNote(testCol.getDb().queryLongScalar("select id from notes"));
n.addTag("test");
n.flush();
i.run();
n.load();
assertThat(n.getTags(), contains("test"));
assertThat(n.getTags(), hasSize(1));
// if add-only mode, count will be 0
i.setImportMode(NoteImporter.ImportMode.IGNORE_MODE);
i.run();
assertEquals(0, i.getTotal());
// and if dupes mode, will reimport everything
assertEquals(5, testCol.cardCount());
i.setImportMode(NoteImporter.ImportMode.ADD_MODE);
i.run();
// includes repeated field
assertEquals(6, i.getTotal());
assertEquals(11, testCol.cardCount());
}
use of com.ichi2.libanki.importer.TextImporter in project AnkiChinaAndroid by ankichinateam.
the class ImportTest method testCsvWithByteOrderMark.
@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testCsvWithByteOrderMark() throws IOException {
String file = Shared.getTestFilePath(InstrumentationRegistry.getInstrumentation().getTargetContext(), "text-utf8-bom.txt");
TextImporter i = new TextImporter(testCol, file);
i.initMapping();
i.run();
Note n = testCol.getNote(testCol.getDb().queryLongScalar("select id from notes"));
assertThat(Arrays.asList(n.getFields()), contains("Hello", "world"));
}
use of com.ichi2.libanki.importer.TextImporter in project AnkiChinaAndroid by ankichinateam.
the class ImportTest method testUcs2CsvWithByteOrderMark.
@Test
@Ignore("Not yet handled")
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testUcs2CsvWithByteOrderMark() throws IOException {
String file = Shared.getTestFilePath(InstrumentationRegistry.getInstrumentation().getTargetContext(), "text-ucs2-be-bom.txt");
TextImporter i = new TextImporter(testCol, file);
i.initMapping();
i.run();
Note n = testCol.getNote(testCol.getDb().queryLongScalar("select id from notes"));
assertThat(Arrays.asList(n.getFields()), contains("Hello", "world"));
}
use of com.ichi2.libanki.importer.TextImporter in project Anki-Android by ankidroid.
the class ImportTest method testUcs2CsvWithByteOrderMark.
@Test
@Ignore("Not yet handled")
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testUcs2CsvWithByteOrderMark() throws IOException {
String file = Shared.getTestFilePath(getTestContext(), "text-ucs2-be-bom.txt");
TextImporter i = new TextImporter(mTestCol, file);
i.initMapping();
i.run();
Note n = mTestCol.getNote(mTestCol.getDb().queryLongScalar("select id from notes"));
assertThat(Arrays.asList(n.getFields()), contains("Hello", "world"));
}
use of com.ichi2.libanki.importer.TextImporter in project Anki-Android by ankidroid.
the class ImportTest method csvManualBasicExample.
@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void csvManualBasicExample() throws IOException, ConfirmModSchemaException {
String file = Shared.getTestFilePath(getTestContext(), "text-anki-manual-csv-single-line.txt");
addFieldToCurrentModel("Third");
TextImporter i = new TextImporter(mTestCol, file);
i.setAllowHtml(true);
i.initMapping();
i.run();
Note n = mTestCol.getNote(mTestCol.getDb().queryLongScalar("select id from notes"));
assertThat(Arrays.asList(n.getFields()), contains("foo bar", "bar baz", "baz quux"));
}
Aggregations