use of com.ichi2.libanki.importer.TextImporter in project Anki-Android by ankidroid.
the class ImportTest method testCsvWithByteOrderMark.
@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testCsvWithByteOrderMark() throws IOException {
String file = Shared.getTestFilePath(getTestContext(), "text-utf8-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 testCsv2.
@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testCsv2() throws IOException, ConfirmModSchemaException {
ModelManager mm = mTestCol.getModels();
Model m = mm.current();
JSONObject f = mm.newField("Three");
mm.addField(m, f);
mm.save(m);
Note n = mTestCol.newNote();
n.setField(0, "1");
n.setField(1, "2");
n.setField(2, "3");
mTestCol.addNote(n);
// an update with unmapped fields should not clobber those fields
String file = Shared.getTestFilePath(getTestContext(), "text-update.txt");
TextImporter i = new TextImporter(mTestCol, file);
i.initMapping();
i.run();
n.load();
List<String> fields = Arrays.asList(n.getFields());
assertThat(fields, contains("1", "x", "3"));
}
use of com.ichi2.libanki.importer.TextImporter in project AnkiChinaAndroid by ankichinateam.
the class ImportTest method csvManualLineBreakExample.
@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void csvManualLineBreakExample() throws IOException {
String file = Shared.getTestFilePath(InstrumentationRegistry.getInstrumentation().getTargetContext(), "text-anki-manual-csv-multi-line.txt");
TextImporter i = new TextImporter(testCol, file);
i.setAllowHtml(true);
i.initMapping();
i.run();
Note n = testCol.getNote(testCol.getDb().queryLongScalar("select id from notes"));
assertThat(Arrays.asList(n.getFields()), contains("hello", "this is\na two line answer"));
}
use of com.ichi2.libanki.importer.TextImporter in project AnkiChinaAndroid by ankichinateam.
the class ImportTest method testCsv2.
@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testCsv2() throws IOException, ConfirmModSchemaException {
Models mm = testCol.getModels();
Model m = mm.current();
JSONObject f = mm.newField("Three");
mm.addField(m, f);
mm.save(m);
Note n = testCol.newNote();
n.setField(0, "1");
n.setField(1, "2");
n.setField(2, "3");
testCol.addNote(n);
// an update with unmapped fields should not clobber those fields
String file = Shared.getTestFilePath(InstrumentationRegistry.getInstrumentation().getTargetContext(), "text-update.txt");
TextImporter i = new TextImporter(testCol, file);
i.initMapping();
i.run();
n.load();
List<String> fields = Arrays.asList(n.getFields());
assertThat(fields, contains("1", "x", "3"));
}
use of com.ichi2.libanki.importer.TextImporter in project AnkiChinaAndroid by ankichinateam.
the class ImportTest method csvManualBasicExample.
@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void csvManualBasicExample() throws IOException, ConfirmModSchemaException {
String file = Shared.getTestFilePath(InstrumentationRegistry.getInstrumentation().getTargetContext(), "text-anki-manual-csv-single-line.txt");
addFieldToCurrentModel("Third");
TextImporter i = new TextImporter(testCol, file);
i.setAllowHtml(true);
i.initMapping();
i.run();
Note n = testCol.getNote(testCol.getDb().queryLongScalar("select id from notes"));
assertThat(Arrays.asList(n.getFields()), contains("foo bar", "bar baz", "baz quux"));
}
Aggregations