Search in sources :

Example 6 with TextImporter

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"));
}
Also used : Note(com.ichi2.libanki.Note) TextImporter(com.ichi2.libanki.importer.TextImporter) Test(org.junit.Test) InstrumentedTest(com.ichi2.anki.tests.InstrumentedTest) SdkSuppress(androidx.test.filters.SdkSuppress)

Example 7 with TextImporter

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"));
}
Also used : JSONObject(com.ichi2.utils.JSONObject) Note(com.ichi2.libanki.Note) Model(com.ichi2.libanki.Model) ModelManager(com.ichi2.libanki.ModelManager) TextImporter(com.ichi2.libanki.importer.TextImporter) Test(org.junit.Test) InstrumentedTest(com.ichi2.anki.tests.InstrumentedTest) SdkSuppress(androidx.test.filters.SdkSuppress)

Example 8 with TextImporter

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"));
}
Also used : Note(com.ichi2.libanki.Note) TextImporter(com.ichi2.libanki.importer.TextImporter) Test(org.junit.Test) SdkSuppress(androidx.test.filters.SdkSuppress)

Example 9 with TextImporter

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"));
}
Also used : JSONObject(com.ichi2.utils.JSONObject) Note(com.ichi2.libanki.Note) Model(com.ichi2.libanki.Model) Models(com.ichi2.libanki.Models) TextImporter(com.ichi2.libanki.importer.TextImporter) Test(org.junit.Test) SdkSuppress(androidx.test.filters.SdkSuppress)

Example 10 with TextImporter

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"));
}
Also used : Note(com.ichi2.libanki.Note) TextImporter(com.ichi2.libanki.importer.TextImporter) Test(org.junit.Test) SdkSuppress(androidx.test.filters.SdkSuppress)

Aggregations

SdkSuppress (androidx.test.filters.SdkSuppress)12 Note (com.ichi2.libanki.Note)12 TextImporter (com.ichi2.libanki.importer.TextImporter)12 Test (org.junit.Test)12 InstrumentedTest (com.ichi2.anki.tests.InstrumentedTest)6 Model (com.ichi2.libanki.Model)2 JSONObject (com.ichi2.utils.JSONObject)2 Ignore (org.junit.Ignore)2 ModelManager (com.ichi2.libanki.ModelManager)1 Models (com.ichi2.libanki.Models)1