Skip to content
This repository has been archived by the owner on Oct 22, 2022. It is now read-only.

Commit

Permalink
fix: star and fork number with comma
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Mar 5, 2019
1 parent 5649b73 commit 4a99551
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/src/github_trending_base.dart
Expand Up @@ -47,14 +47,17 @@ Future<List<TrendingRepository>> getTrendingRepositories() async {
?.parent
?.innerHtml
?.replaceFirst(RegExp(r'^[\s\S]*svg>'), '')
?.replaceAll(',', '')
?.trim();

var starCount = starCountStr == null ? null : int.tryParse(starCountStr);

var forkCountStr = item
.querySelector('.octicon-repo-forked')
?.parent
?.innerHtml
?.replaceFirst(RegExp(r'^[\s\S]*svg>'), '')
?.replaceAll(',', '')
?.trim();
var forkCount = forkCountStr == null ? null : int.tryParse(forkCountStr);

Expand Down
12 changes: 12 additions & 0 deletions test/github_trending_test.dart
Expand Up @@ -20,10 +20,22 @@ void main() {
});
});

test('star and fork count', () {
// make sure at least one item has star or fork
// to ensure no parse error
var itemHasStar = items.where((item) => item.starCount != null);
expect(itemHasStar, isNotEmpty);

var itemHasFork = items.where((item) => item.forkCount != null);
expect(itemHasFork, isNotEmpty);
});

test('primary language', () {
items.forEach((item) {
if (item.primaryLanguage != null) {
expect(item.primaryLanguage.name, isNotNull);

// CSS color format
expect(
RegExp(r'(#\w{6})').hasMatch(item.primaryLanguage.color), isTrue);
}
Expand Down

0 comments on commit 4a99551

Please sign in to comment.