Fix some bugs
This commit is contained in:
parent
763924531f
commit
03e9182cb1
|
@ -96,12 +96,12 @@ class Radical {
|
|||
this.meaning = meaning;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() =>
|
||||
{
|
||||
'symbol': symbol,
|
||||
'forms': forms,
|
||||
'meaning': meaning
|
||||
};
|
||||
Map<String, dynamic> toJson() =>
|
||||
{
|
||||
if (symbol != null) 'symbol': symbol,
|
||||
if (forms != null) 'forms': forms,
|
||||
if (meaning != null) 'meaning': meaning
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -116,14 +116,42 @@ class KanjiResult {
|
|||
String meaning;
|
||||
List<String> kunyomi;
|
||||
List<String> onyomi;
|
||||
List<YomiExample> onyomiExamples;
|
||||
List<YomiExample> kunyomiExamples;
|
||||
List<YomiExample> onyomiExamples;
|
||||
Radical radical;
|
||||
List<String> parts;
|
||||
String strokeOrderDiagramUri;
|
||||
String strokeOrderSvgUri;
|
||||
String strokeOrderGifUri;
|
||||
String uri;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
|
||||
if (found == false) return {
|
||||
'query': query,
|
||||
'found': found
|
||||
};
|
||||
|
||||
return {
|
||||
'query': query,
|
||||
'found': found,
|
||||
'taughtIn': taughtIn,
|
||||
'jlptLevel': jlptLevel,
|
||||
'newspaperFrequencyRank': newspaperFrequencyRank.toString(),
|
||||
'strokeCount': strokeCount,
|
||||
'meaning': meaning,
|
||||
'kunyomi': kunyomi,
|
||||
'onyomi': onyomi,
|
||||
'onyomiExamples': onyomiExamples.map((onyomiExample) => onyomiExample.toJson()).toList(),
|
||||
'kunyomiExamples': kunyomiExamples.map((kunyomiExample) => kunyomiExample.toJson()).toList(),
|
||||
'radical': radical.toJson(),
|
||||
'parts': parts,
|
||||
'strokeOrderDiagramUri': strokeOrderDiagramUri,
|
||||
'strokeOrderSvgUri': strokeOrderSvgUri,
|
||||
'strokeOrderGifUri': strokeOrderGifUri,
|
||||
'uri': uri
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class ExampleSentencePiece {
|
||||
|
|
|
@ -8,9 +8,9 @@ final htmlUnescape = html_entities.HtmlUnescape();
|
|||
|
||||
// TODO: Put public facing types in this file.
|
||||
|
||||
const String JISHO_API = 'https://jisho.org/api/v1/search/words';
|
||||
const String SCRAPE_BASE_URI = 'https://jisho.org/search/';
|
||||
const String STROKE_ORDER_DIAGRAM_BASE_URI = 'https://classic.jisho.org/static/images/stroke_diagrams/';
|
||||
const String JISHO_API = 'http://jisho.org/api/v1/search/words';
|
||||
const String SCRAPE_BASE_URI = 'http://jisho.org/search/';
|
||||
const String STROKE_ORDER_DIAGRAM_BASE_URI = 'http://classic.jisho.org/static/images/stroke_diagrams/';
|
||||
|
||||
/* KANJI SEARCH FUNCTIONS START */
|
||||
|
||||
|
|
|
@ -17,20 +17,20 @@ void test_local_functions() async {
|
|||
|
||||
test('uriForKanjiSearch', () {
|
||||
final result = uriForKanjiSearch('時');
|
||||
expect(result, 'https://jisho.org/search/%E6%99%82%23kanji');
|
||||
expect(result, 'http://jisho.org/search/%E6%99%82%23kanji');
|
||||
});
|
||||
|
||||
test('getUriForStrokeOrderDiagram', () {
|
||||
final result = getUriForStrokeOrderDiagram('時');
|
||||
expect(result, 'https://classic.jisho.org/static/images/stroke_diagrams/26178_frames.png');
|
||||
expect(result, 'http://classic.jisho.org/static/images/stroke_diagrams/26178_frames.png');
|
||||
});
|
||||
|
||||
test('uriForPhraseSearch', () {
|
||||
final result = uriForPhraseSearch('時間');
|
||||
expect(result, 'https://jisho.org/api/v1/search/words?keyword=%E6%99%82%E9%96%93');
|
||||
expect(result, 'http://jisho.org/api/v1/search/words?keyword=%E6%99%82%E9%96%93');
|
||||
});
|
||||
|
||||
final kanjiPage = (await http.get('https://jisho.org/search/%E6%99%82%23kanji')).body;
|
||||
final kanjiPage = (await http.get('http://jisho.org/search/%E6%99%82%23kanji')).body;
|
||||
|
||||
test('containsKanjiGlyph', () {
|
||||
final result = containsKanjiGlyph(kanjiPage, '時');
|
||||
|
@ -277,10 +277,10 @@ void test_local_functions() async {
|
|||
meaning: 'sun, day'
|
||||
);
|
||||
expectedResult.parts = ['土', '寸', '日'];
|
||||
expectedResult.strokeOrderDiagramUri = 'https://classic.jisho.org/static/images/stroke_diagrams/26178_frames.png';
|
||||
expectedResult.strokeOrderDiagramUri = 'http://classic.jisho.org/static/images/stroke_diagrams/26178_frames.png';
|
||||
expectedResult.strokeOrderSvgUri = 'http://d1w6u4xc3l95km.cloudfront.net/kanji-2015-03/06642.svg';
|
||||
expectedResult.strokeOrderGifUri = 'https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/3c.gif';
|
||||
expectedResult.uri = 'https://jisho.org/search/%E6%99%82%23kanji';
|
||||
expectedResult.strokeOrderGifUri = 'https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/6642.gif';
|
||||
expectedResult.uri = 'http://jisho.org/search/%E6%99%82%23kanji';
|
||||
|
||||
expect(
|
||||
json.encode(result),
|
||||
|
|
|
@ -22,7 +22,7 @@ void runTestCases(List<String> testCaseFiles, String apiFunction) async {
|
|||
switch(apiFunction) {
|
||||
case 'searchForKanji': {
|
||||
final result = await jisho.searchForKanji(testCase['query']);
|
||||
expect(result, jsonDecode(testCase['expectedResult']));
|
||||
expect(result.toJson(), testCase['expectedResult']);
|
||||
break;
|
||||
}
|
||||
case 'searchForExamples': {
|
||||
|
|
Loading…
Reference in New Issue