-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6c5dd2
commit e85ae3c
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package languages | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/codersrank-org/repo_info_extractor/v2/librarydetection" | ||
) | ||
|
||
// NewDartScriptAnalyzer constructor | ||
func NewDartScriptAnalyzer() librarydetection.Analyzer { | ||
return &dartScriptAnalyzer{} | ||
} | ||
|
||
type dartScriptAnalyzer struct{} | ||
|
||
func (a *dartScriptAnalyzer) ExtractLibraries(contents string) ([]string, error) { | ||
// for imports like this: import 'dart:developer' as dev; OR import 'dart:developer'; | ||
importRegex, err := regexp.Compile(`import '([:a-zA-Z0-9_-]+)'(?:|as)`) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// for imports like this: import 'package:flutter/material.dart'; | ||
importRegex2, err := regexp.Compile(`import '([:a-zA-Z0-9_-]+)/[\.a-zA-Z0-9_-]+'`) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return executeRegexes(contents, []*regexp.Regexp{importRegex, importRegex2}), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package languages_test | ||
|
||
import ( | ||
"io/ioutil" | ||
|
||
. "github.com/onsi/ginkgo" | ||
|
||
"github.com/codersrank-org/repo_info_extractor/v2/librarydetection/languages" | ||
) | ||
|
||
var _ = Describe("DartLibraryDetection", func() { | ||
fixture, err := ioutil.ReadFile("./fixtures/dart.fixture") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
expectedLibraries := []string{ | ||
"dart:async", | ||
"dart:developer", | ||
"package:flutter", | ||
} | ||
|
||
analyzer := languages.NewDartScriptAnalyzer() | ||
|
||
Describe("Extract Dart Libraries", func() { | ||
It("Should be able to extract libraries", func() { | ||
libs, err := analyzer.ExtractLibraries(string(fixture)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
assertSameUnordered(libs, expectedLibraries) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import 'dart:async'; | ||
import 'dart:developer' as dev; | ||
import 'package:flutter/material.dart'; |