Fix some bugs

This commit is contained in:
Oystein Kristoffer Tveit 2020-06-11 11:50:16 +02:00
parent 763924531f
commit 03e9182cb1
4 changed files with 46 additions and 18 deletions

View File

@ -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 {

View File

@ -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 */

View File

@ -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),

View File

@ -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': {