Best Gauge code snippet using plugin.language
app_subtitle_test.go
Source:app_subtitle_test.go
...14 "github.com/fatih/set"15 "github.com/stretchr/testify/assert"16 "github.com/stretchr/testify/require"17 "github.com/tympanix/supper/types"18 "golang.org/x/text/language"19)20type subtitle struct {21 types.Media22 lang language.Tag23 hi bool24}25func (s subtitle) String() string { return "Subtitle: " + s.Media.String() }26func (s subtitle) ForMedia() types.Media { return s.Media }27func (s subtitle) HearingImpaired() bool { return s.hi }28func (s subtitle) Language() language.Tag { return s.lang }29func (s subtitle) TypeSubtitle() (types.Subtitle, bool) { return s, true }30func (s subtitle) TypeEpisode() (types.Episode, bool) { return nil, false }31func (s subtitle) TypeMovie() (types.Movie, bool) { return nil, false }32type online struct {33 types.Subtitle34 data []byte35}36func (o online) Download() (io.ReadCloser, error) {37 return ioutil.NopCloser(bytes.NewBuffer(o.data)), nil38}39func (o online) Link() string {40 return ""41}42type onlineError struct {43 types.Subtitle44}45func (o onlineError) Download() (io.ReadCloser, error) {46 return nil, errors.New("test download subtitle error")47}48func (o onlineError) Link() string {49 return ""50}51type mockSaveSubtitleError struct {52 types.Video53}54func (mockSaveSubtitleError) SaveSubtitle(io.Reader, language.Tag) (types.LocalSubtitle, error) {55 return nil, errors.New("test save subtitle")56}57type fakeEvaluator func(types.Media, types.Media) float3258func (e fakeEvaluator) Evaluate(m types.Media, n types.Media) float32 {59 return e(m, n)60}61type subtitleTester interface {62 Pre(*testing.T, []types.LocalMedia)63 Input() string64 Mock(types.LocalMedia) types.LocalMedia65 Test(*testing.T, types.LocalSubtitle)66 Post(*testing.T, []types.Video, []types.LocalSubtitle)67}68type fakePlugin func(types.LocalSubtitle) error69func (p fakePlugin) Run(s types.LocalSubtitle) error {70 return p(s)71}72func (p fakePlugin) Name() string {73 return "fakeplugin"74}75type fakeProviderError struct{}76func (p fakeProviderError) SearchSubtitles(m types.LocalMedia) ([]types.OnlineSubtitle, error) {77 return nil, errors.New("test provider error")78}79func (p fakeProviderError) ResolveSubtitle(l types.Linker) (types.Downloadable, error) {80 return nil, errors.New("test provider does not support resolving subtitles")81}82func must(m types.LocalMedia, err error) types.LocalMedia {83 if err != nil {84 panic(err)85 }86 return m87}88type fakeTimedProvider struct {89 delay time.Duration90 fakeProvider91 last time.Time92}93func (p *fakeTimedProvider) SearchSubtitles(m types.LocalMedia) ([]types.OnlineSubtitle, error) {94 fmt.Println(time.Since(p.last))95 if time.Since(p.last) < p.delay {96 return nil, errors.New("expected delay to occur")97 }98 p.last = time.Now()99 fmt.Println(p.last)100 return p.fakeProvider.SearchSubtitles(m)101}102func (p *fakeTimedProvider) reset() {103 p.last = time.Unix(0, 0)104}105func TestDownloadSubtitles(t *testing.T) {106 config := defaultConfig107 config.strict = true108 config.languages = set.New(language.German)109 err := performSubtitleTest(t, subtitleLangTester(language.German), config)110 assert.NoError(t, err)111 cleanRenameTest(t)112}113func TestSubtitlePlugins(t *testing.T) {114 config := defaultConfig115 var results []types.LocalSubtitle116 config.plugins = []types.Plugin{117 fakePlugin(func(s types.LocalSubtitle) error {118 results = append(results, s)119 return nil120 }),121 }122 config.languages = set.New(language.German)123 err := performSubtitleTest(t, pluginTester{&results}, config)124 assert.NoError(t, err)125 cleanRenameTest(t)126}127func TestSubtitlePluginError(t *testing.T) {128 config := defaultConfig129 config.strict = true130 config.plugins = []types.Plugin{131 fakePlugin(func(s types.LocalSubtitle) error {132 return errors.New("test plugin error")133 }),134 }135 config.languages = set.New(language.German)136 err := performSubtitleTest(t, subtitleLangTester(language.German), config)137 assert.Error(t, err)138 assert.Contains(t, err.Error(), "test plugin error")139 cleanRenameTest(t)140}141func TestSubtitleNoMedia(t *testing.T) {142 app := New(defaultConfig)143 c := notify.AsyncDiscard()144 defer close(c)145 _, err := app.DownloadSubtitles(nil, set.New(language.English), c)146 assert.Error(t, err)147 assert.Contains(t, err.Error(), "no media")148}149func TestSubtitleNoLanguage(t *testing.T) {150 app := New(defaultConfig)151 c := notify.AsyncDiscard()152 defer close(c)153 _, err := app.DownloadSubtitles(list.NewLocalMedia(), nil, c)154 assert.Error(t, err)155 assert.Contains(t, err.Error(), "no languages")156}157func TestSubtitleNoVideo(t *testing.T) {158 app := New(defaultConfig)159 c := notify.AsyncDiscard()160 defer close(c)161 _, err := app.DownloadSubtitles(list.NewLocalMedia(), set.New(language.English), c)162 assert.Error(t, err)163 assert.Contains(t, err.Error(), "no video")164}165func TestSubtitleScore(t *testing.T) {166 config := defaultConfig167 config.strict = true168 config.evaluator = fakeEvaluator(func(m types.Media, n types.Media) float32 {169 return 0.01170 })171 config.languages = set.New(language.German)172 config.score = 100173 err := performSubtitleTest(t, subtitleLangTester(language.German), config)174 assert.Error(t, err)175 assert.Contains(t, err.Error(), "Score too low")176 assert.Contains(t, err.Error(), "1%")177 cleanRenameTest(t)178}179func TestSubtitleProviderError(t *testing.T) {180 config := defaultConfig181 config.strict = true182 config.providers = []types.Provider{183 fakeProviderError{},184 }185 config.languages = set.New(language.German)186 err := performSubtitleTest(t, subtitleLangTester(language.German), config)187 assert.Error(t, err)188 assert.Contains(t, err.Error(), "test provider error")189 cleanRenameTest(t)190}191func TestSubtitleNoneAvailable(t *testing.T) {192 config := defaultConfig193 config.strict = true194 config.languages = set.New(language.Russian)195 err := performSubtitleTest(t, skipSubtitlesTest{}, config)196 assert.NoError(t, err)197 cleanRenameTest(t)198}199func TestSubtitleDryRun(t *testing.T) {200 config := defaultConfig201 config.strict = true202 config.dry = true203 // when dry run, provider should never be called204 config.providers = []types.Provider{205 fakeProviderError{},206 }207 config.languages = set.New(language.German)208 err := performSubtitleTest(t, skipSubtitlesTest{}, config)209 assert.NoError(t, err)210 cleanRenameTest(t)211}212func TestSubtitleUnsatisfied(t *testing.T) {213 config := defaultConfig214 config.strict = true215 // media is always unsatisfied (score = 0.0)216 config.evaluator = fakeEvaluator(func(m types.Media, n types.Media) float32 {217 return 0.0218 })219 config.languages = set.New(language.German)220 err := performSubtitleTest(t, skipSubtitlesTest{}, config)221 assert.Error(t, err)222 assert.Contains(t, err.Error(), "No subtitles satisfied media")223 cleanRenameTest(t)224}225func TestSubtitleDownloadError(t *testing.T) {226 config := defaultConfig227 config.strict = true228 config.providers = []types.Provider{229 fakeProviderDownloadError{[]language.Tag{230 language.English,231 language.German,232 language.Spanish,233 }},234 }235 config.languages = set.New(language.German)236 err := performSubtitleTest(t, subtitleLangTester(language.German), config)237 assert.Error(t, err)238 assert.Contains(t, err.Error(), "test download subtitle error")239 cleanRenameTest(t)240}241func TestSubtitleSaveError(t *testing.T) {242 defer cleanRenameTest(t)243 config := defaultConfig244 config.strict = true245 config.languages = set.New(language.German)246 err := performSubtitleTest(t, saveErrorSubtitleTest{}, config)247 require.Error(t, err)248 assert.Contains(t, err.Error(), "test save subtitle")249}250func TestSubtitleDelay(t *testing.T) {251 defer cleanRenameTest(t)252 const testDelay = 250 * time.Millisecond253 config := defaultConfig254 config.strict = true255 config.languages = set.New(language.German)256 timedProvider := &fakeTimedProvider{257 testDelay,258 fakeProvider{[]language.Tag{259 language.German,260 }},261 time.Unix(0, 0),262 }263 config.providers = []types.Provider{264 timedProvider,265 }266 // first run, without delay, should return error267 err := performSubtitleTest(t, subtitleLangTester(language.German), config)268 require.Error(t, err)269 assert.Contains(t, err.Error(), "expected delay to occur")270 cleanRenameTest(t)271 // second run, with delay, should not return error272 timedProvider.reset()273 config.delay = time.Duration(testDelay)274 err = performSubtitleTest(t, subtitleLangTester(language.German), config)275 assert.NoError(t, err)276}277func TestSubtitleInvalidLanguages(t *testing.T) {278 defer cleanRenameTest(t)279 config := defaultConfig280 config.strict = true281 config.languages = set.New(42)282 err := performSubtitleTest(t, skipSubtitlesTest{}, config)283 require.Error(t, err)284 assert.Contains(t, err.Error(), "unknown language")285}286func copyTestFiles(src, dst string) error {287 files, err := ioutil.ReadDir(src)288 if err != nil {289 return err290 }291 if err := os.MkdirAll(dst, os.ModePerm); err != nil {292 return err293 }294 for _, f := range files {295 if f.IsDir() {296 continue297 }298 i, err := os.Open(filepath.Join(src, f.Name()))299 if err != nil {300 return err301 }302 defer i.Close()303 o, err := os.Create(filepath.Join(dst, f.Name()))304 if err != nil {305 return err306 }307 defer o.Close()308 _, err = io.Copy(o, i)309 if err != nil {310 return err311 }312 }313 return nil314}315func performSubtitleTest(t *testing.T, test subtitleTester, config types.Config) error {316 app := New(config)317 require.NoError(t, copyTestFiles(test.Input(), "out"))318 media, err := app.FindMedia("out")319 require.NoError(t, err)320 mocked := media.List()321 for i, m := range mocked {322 mocked[i] = test.Mock(m)323 }324 media = list.NewLocalMedia(mocked...)325 test.Pre(t, media.List())326 c := notify.AsyncDiscard()327 defer close(c)328 subs, err := app.DownloadSubtitles(media, config.Languages(), c)329 if err != nil {330 return err331 }332 for _, s := range subs {333 test.Test(t, s)334 }335 test.Post(t, media.FilterVideo().List(), subs)336 return nil337}338type subtitleLangTester language.Tag339func (subtitleLangTester) Pre(t *testing.T, l []types.LocalMedia) {340 assert.Equal(t, len(res), len(l))341}342func (subtitleLangTester) Mock(m types.LocalMedia) types.LocalMedia {343 return m344}345func (subtitleLangTester) Input() string {346 return "test"347}348func (l subtitleLangTester) Test(t *testing.T, s types.LocalSubtitle) {349 assert.Equal(t, s.Language(), language.Tag(l))350}351func (subtitleLangTester) Post(t *testing.T, m []types.Video, l []types.LocalSubtitle) {352 assert.Equal(t, len(m), len(l))353}354type pluginTester struct {355 runs *[]types.LocalSubtitle356}357func (p pluginTester) Pre(t *testing.T, l []types.LocalMedia) {358 assert.Equal(t, len(res), len(l))359}360func (p pluginTester) Input() string {361 return "test"362}363func (p pluginTester) Mock(m types.LocalMedia) types.LocalMedia {...
help.go
Source:help.go
...16func (plugin HelpPlugin) Config() IgorConfig {17 return plugin.config18}19type helpConfig struct {20 languages map[string]config.LanguagePluginDetails21 chosenLanguage string22}23// Languages returns the languages available for the plugin24func (config helpConfig) Languages() map[string]config.LanguagePluginDetails {25 return config.languages26}27// ChosenLanguage returns the language active for this plugin28func (config helpConfig) ChosenLanguage() string {29 return config.chosenLanguage30}31// Help instantiates the HelpPlugin32func Help(request slack.Request) IgorPlugin {33 pluginName := "help"34 pluginConfig := helpConfig{35 languages: getPluginLanguages(pluginName),36 }37 plugin := HelpPlugin{38 name: pluginName,39 request: request,40 config: pluginConfig,41 }42 return plugin43}44// Work parses the request and ensures a request comes through if any triggers45// are matched. Handled triggers:46//47// * help48// * introduce yourself49// * tell me about yourself50func (plugin HelpPlugin) Work() (slack.Response, error) {51 response := slack.Response{}52 message, language := getCommandName(plugin)53 plugin.config.chosenLanguage = language54 switch message {55 case "help":56 tmpresponse, err := plugin.handleHelp(response)57 if err != nil {58 return tmpresponse, err59 }60 response = tmpresponse61 case "intro":62 response = plugin.handleIntroduction(response)63 case "tellme":64 response = plugin.handleTellMe(response)65 case "whoami":66 response = plugin.handleWhoAmI(response)67 }68 if response.Text == "" {69 return response, CreateNoMatchError("Nothing found")70 }71 return response, nil72}73// Describe provides the triggers HelpPlugin can handle74func (plugin HelpPlugin) Describe(language string) map[string]string {75 descriptions := make(map[string]string)76 for _, values := range getAllCommands(plugin, language) {77 descriptions[values.Command] = values.Description78 }79 return descriptions80}81func (plugin HelpPlugin) handleHelp(response slack.Response) (slack.Response, error) {82 commandDetails := getCommandDetails(plugin, "help")83 response.Text = commandDetails.Texts["response_text"]84 config, err := config.GeneralConfig()85 if err != nil {86 return response, err87 }88 attach := slack.Attachment{Text: ""}89 allPlugins := GetPlugins(plugin.request, config)90 for languageName, details := range config.Languages {91 if languageName != plugin.config.chosenLanguage {92 attach.Text += details.Language["description"] + "\n"93 }94 }95 if attach.Text != "" {96 response.AddAttachment(attach)97 }98 c := make(chan slack.Attachment)99 for _, igor := range allPlugins {100 go func(igor IgorPlugin, language string) {101 var buffer bytes.Buffer102 for command, description := range igor.Describe(language) {103 buffer.WriteString("- *" + command + "*: " + description + "\n")104 }105 attach := slack.Attachment{}106 attach.Title = igor.Description(language)107 attach.Text = buffer.String()108 attach.EnableMarkdownFor("text")109 c <- attach110 }(igor, plugin.config.chosenLanguage)111 }112 for i := 0; i < len(allPlugins); i++ {113 response.AddAttachment(<-c)114 }115 return response, nil116}117func (plugin HelpPlugin) handleIntroduction(response slack.Response) slack.Response {118 commandDetails := getCommandDetails(plugin, "intro")119 response.Text = commandDetails.Texts["response_text"]120 response.SetPublic()121 attach := slack.Attachment{}122 attach.Title = commandDetails.Texts["attach_title"]123 attach.Text = commandDetails.Texts["attach_text"]124 attach.EnableMarkdownFor("text")125 response.AddAttachment(attach)126 return response127}128func (plugin HelpPlugin) handleTellMe(response slack.Response) slack.Response {129 commandDetails := getCommandDetails(plugin, "tellme")130 response.Text = commandDetails.Texts["response_text"]131 attach := slack.Attachment{}132 attach.Title = "GitHub"133 attach.Text = commandDetails.Texts["github_text"]134 response.AddAttachment(attach)135 attach = slack.Attachment{}136 attach.Title = "ig.nore.me"137 attach.Text = commandDetails.Texts["site_text"]138 response.AddAttachment(attach)139 return response140}141func (plugin HelpPlugin) handleWhoAmI(response slack.Response) slack.Response {142 commandDetails := getCommandDetails(plugin, "whoami")143 request := plugin.request144 response.Text = commandDetails.Texts["response_text"]145 attach := slack.Attachment{}146 attach.Title = commandDetails.Texts["attach_title"]147 attach.AddField(slack.Field{Title: "Name", Value: request.UserName, Short: true})148 attach.AddField(slack.Field{Title: "UserID", Value: request.UserID, Short: true})149 attach.AddField(slack.Field{Title: "Channel", Value: request.ChannelName, Short: true})150 attach.AddField(slack.Field{Title: "ChannelID", Value: request.ChannelID, Short: true})151 attach.AddField(slack.Field{Title: "Team", Value: request.TeamDomain, Short: true})152 attach.AddField(slack.Field{Title: "TeamID", Value: request.TeamID, Short: true})153 response.AddAttachment(attach)154 return response155}156// Description returns a global description of the plugin157func (plugin HelpPlugin) Description(language string) string {158 return getDescriptionText(plugin, language)159}160// Name returns the name of the plugin161func (plugin HelpPlugin) Name() string {162 return plugin.name163}164// Message returns a formatted version of the original message165func (plugin HelpPlugin) Message() string {166 return strings.ToLower(plugin.request.Text)167}...
plugins.go
Source:plugins.go
...72 softmatch := make(map[string]string)73 if subCommandArray != nil {74 subCommand = strings.ToLower(subCommandArray[1])75 }76 for language, details := range plugin.Config().Languages() {77 for name, value := range details.Commands {78 matchArray := reMain.FindStringSubmatch(value.Command)79 match := ""80 if matchArray != nil {81 match = strings.ToLower(matchArray[1])82 }83 if strings.ToLower(plugin.Message()) == strings.ToLower(value.Command) {84 return name, language85 } else if match != "" && match == subCommand {86 softmatch[language] = name87 }88 }89 }90 if len(softmatch) > 0 {91 for language, name := range softmatch {92 return name, language93 }94 }95 return "", ""96}97func getCommandDetails(plugin IgorPlugin, commandName string) config.LanguagePluginCommandDetails {98 return getAllCommands(plugin, "")[commandName]99}100func getAllCommands(plugin IgorPlugin, language string) map[string]config.LanguagePluginCommandDetails {101 language = getPluginLanguage(plugin, language)102 return plugin.Config().Languages()[language].Commands103}104func getDescriptionText(plugin IgorPlugin, language string) string {105 language = getPluginLanguage(plugin, language)106 return plugin.Config().Languages()[language].Description107}108func getPluginLanguage(plugin IgorPlugin, language string) string {109 if language == "" {110 language = plugin.Config().ChosenLanguage()111 }112 if _, ok := plugin.Config().Languages()[language]; !ok {113 generalConfig, _ := config.GeneralConfig()114 language = generalConfig.DefaultLanguage115 }116 return language117}118func getPluginLanguages(pluginname string) map[string]config.LanguagePluginDetails {119 generalConfig, _ := config.GeneralConfig()120 details := make(map[string]config.LanguagePluginDetails)121 for language, langConfig := range generalConfig.Languages {122 if val, ok := langConfig.Plugins[pluginname]; ok {123 details[language] = val124 }125 }126 return details127}...
language
Using AI Code Generation
1import (2func main() {3 p, err := plugin.Open("plugin.so")4 if err != nil {5 fmt.Println(err)6 }7 f, err := p.Lookup("Language")8 if err != nil {9 fmt.Println(err)10 }11 language, ok := f.(func() string)12 if !ok {13 fmt.Println("unexpected type from module symbol")14 }15 fmt.Println(language())16}
language
Using AI Code Generation
1import (2func main() {3 p, err := plugin.Open("plugin.so")4 if err != nil {5 panic(err)6 }7 symGreeter, err := p.Lookup("Greeter")8 if err != nil {9 panic(err)10 }11 greeter, ok := symGreeter.(Greeter)12 if !ok {13 panic("unexpected type from module symbol")14 }15 fmt.Println(greeter.Greet("Gopher"))16}
language
Using AI Code Generation
1public class Class1 {2 public void doSomething() {3 Plugin plugin = new Plugin();4 plugin.language();5 }6}7public class Class2 {8 public void doSomething() {9 Plugin plugin = new Plugin();10 plugin.language();11 }12}13public class Class3 {14 public void doSomething() {15 Plugin plugin = new Plugin();16 plugin.language();17 }18}19public class Class4 {20 public void doSomething() {21 Plugin plugin = new Plugin();22 plugin.language();23 }24}25public class Class5 {26 public void doSomething() {27 Plugin plugin = new Plugin();28 plugin.language();29 }30}31public class Class6 {32 public void doSomething() {33 Plugin plugin = new Plugin();34 plugin.language();35 }36}37public class Class7 {38 public void doSomething() {39 Plugin plugin = new Plugin();40 plugin.language();41 }42}43public class Class8 {44 public void doSomething() {45 Plugin plugin = new Plugin();46 plugin.language();47 }48}49public class Class9 {50 public void doSomething() {51 Plugin plugin = new Plugin();52 plugin.language();53 }54}55public class Class10 {56 public void doSomething() {57 Plugin plugin = new Plugin();58 plugin.language();59 }60}61public class Class11 {62 public void doSomething() {63 Plugin plugin = new Plugin();64 plugin.language();65 }66}67public class Class12 {68 public void doSomething() {69 Plugin plugin = new Plugin();70 plugin.language();71 }
language
Using AI Code Generation
1import "fmt"2type Language struct{}3func (l *Language) Print() {4 fmt.Println("Hello World")5}6func New() *Language {7 return &Language{}8}9import "fmt"10type Language struct{}11func (l *Language) Print() {12 fmt.Println("Hello World")13}14func New() *Language {15 return &Language{}16}17func Open(path string) (*Plugin, error)18func (p *Plugin) Lookup(name string) (Symbol, error)
language
Using AI Code Generation
1func (p *Plugin) Hello() string {2}3func (p *Plugin) Hello2() string {4}5func main() {6 p, err := plugin.Open("plugin.so")7 if err != nil {8 panic(err)9 }10 hello, err := p.Lookup("Hello")11 if err != nil {12 panic(err)13 }14 str, err := hello.(func() string)()15 if err != nil {16 panic(err)17 }18 fmt.Println(str)19 hello2, err := p.Lookup("Hello2")20 if err != nil {21 panic(err)22 }23 str2, err := hello2.(func() string)()24 if err != nil {25 panic(err)26 }27 fmt.Println(str2)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!