github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/autocomplete/autocomplete_test.go (about) 1 package cmdautocomplete_test 2 3 import ( 4 "testing" 5 6 _ "github.com/lmorg/murex/builtins" 7 "github.com/lmorg/murex/lang" 8 "github.com/lmorg/murex/test/count" 9 ) 10 11 func TestAutocomplete(t *testing.T) { 12 count.Tests(t, 1) 13 14 block := []rune( 15 `autocomplete set foobar { [{ 16 "AnyValue": true, 17 "AllowMultiple": true, 18 "ExecCmdline": true, 19 "Flags": [ "hello", "world" ] 20 }] } 21 22 autocomplete get foobar -> pretty`) 23 24 expected := `[ 25 { 26 "DynamicPreview": "", 27 "IncFiles": false, 28 "FileRegexp": "", 29 "IncDirs": false, 30 "IncExePath": false, 31 "IncExeAll": false, 32 "IncManPage": false, 33 "Flags": [ 34 "hello", 35 "world" 36 ], 37 "FlagsDesc": null, 38 "Dynamic": "", 39 "DynamicDesc": "", 40 "ListView": false, 41 "MapView": false, 42 "FlagValues": null, 43 "Optional": false, 44 "AllowMultiple": true, 45 "AllowNoFlagValue": false, 46 "Goto": "", 47 "Alias": "", 48 "NestedCommand": false, 49 "ImportCompletion": "", 50 "AnyValue": true, 51 "AllowAny": false, 52 "AutoBranch": false, 53 "ExecCmdline": true, 54 "CacheTTL": 5, 55 "IgnorePrefix": false 56 } 57 ] 58 ` 59 60 lang.InitEnv() 61 62 fork := lang.ShellProcess.Fork(lang.F_NO_STDIN | lang.F_CREATE_STDOUT | lang.F_CREATE_STDERR) 63 exitNum, err := fork.Execute(block) 64 if exitNum != 0 { 65 t.Errorf("None zero exit number: %d", exitNum) 66 } 67 if err != nil { 68 t.Errorf("Error in fork.Execute(): %s", err.Error()) 69 } 70 71 stdout, err := fork.Stdout.ReadAll() 72 if err != nil { 73 t.Errorf("Error in fork.Stdout.ReadAll(): %s", err.Error()) 74 } 75 76 stderr, err := fork.Stderr.ReadAll() 77 if err != nil { 78 t.Errorf("Error in fork.Stderr.ReadAll(): %s", err.Error()) 79 } 80 if len(stderr) > 0 { 81 t.Errorf("Stderr should be empty: %s", string(stderr)) 82 } 83 84 if string(stdout) != expected { 85 t.Error("Stdout doesn't match expected:") 86 t.Logf(" Expected: %s", expected) 87 t.Logf(" Actual: %s", string(stdout)) 88 } 89 }