Best Gauge code snippet using util.ConvertPathToURI
diagnostics.go
Source:diagnostics.go
...58 return diagnostics, nil59}60func createValidationDiagnostics(errors []error, diagnostics map[lsp.DocumentURI][]lsp.Diagnostic) {61 for _, err := range errors {62 uri := util.ConvertPathToURI(err.(validation.StepValidationError).FileName())63 s := err.(validation.StepValidationError).Step()64 d := createDiagnostic(uri, err.(validation.StepValidationError).Message(), s.LineNo-1, s.LineSpanEnd-1, 1)65 if err.(validation.StepValidationError).ErrorType() == gm.StepValidateResponse_STEP_IMPLEMENTATION_NOT_FOUND {66 d.Code = err.(validation.StepValidationError).Suggestion()67 }68 diagnostics[uri] = append(diagnostics[uri], d)69 }70}71func validateSpecifications(specs []*gauge.Specification, conceptDictionary *gauge.ConceptDictionary) []error {72 if lRunner.runner == nil {73 return []error{}74 }75 vErrs := validation.NewValidator(specs, lRunner.runner, conceptDictionary).Validate()76 return validation.FilterDuplicates(vErrs)77}78func validateSpecs(conceptDictionary *gauge.ConceptDictionary, diagnostics map[lsp.DocumentURI][]lsp.Diagnostic) error {79 specFiles := util.GetSpecFiles(util.GetSpecDirs())80 specs := make([]*gauge.Specification, 0)81 for _, specFile := range specFiles {82 uri := util.ConvertPathToURI(specFile)83 if _, ok := diagnostics[uri]; !ok {84 diagnostics[uri] = make([]lsp.Diagnostic, 0)85 }86 content, err := getContentFromFileOrDisk(specFile)87 if err != nil {88 return fmt.Errorf("unable to read file %s", err)89 }90 spec, res, err := new(parser.SpecParser).Parse(content, conceptDictionary, specFile)91 if err != nil {92 return err93 }94 createDiagnostics(res, diagnostics)95 if res.Ok {96 specs = append(specs, spec)97 }98 }99 createValidationDiagnostics(validateSpecifications(specs, conceptDictionary), diagnostics)100 return nil101}102func validateConcepts(diagnostics map[lsp.DocumentURI][]lsp.Diagnostic) (*gauge.ConceptDictionary, error) {103 conceptFiles := util.GetConceptFiles()104 conceptDictionary := gauge.NewConceptDictionary()105 for _, conceptFile := range conceptFiles {106 uri := util.ConvertPathToURI(conceptFile)107 if _, ok := diagnostics[uri]; !ok {108 diagnostics[uri] = make([]lsp.Diagnostic, 0)109 }110 content, err := getContentFromFileOrDisk(conceptFile)111 if err != nil {112 return nil, fmt.Errorf("unable to read file %s", err)113 }114 cpts, pRes := new(parser.ConceptParser).Parse(content, conceptFile)115 pErrs, err := parser.AddConcept(cpts, conceptFile, conceptDictionary) // nolint116 if err != nil {117 return nil, err118 }119 pRes.ParseErrors = append(pRes.ParseErrors, pErrs...)120 createDiagnostics(pRes, diagnostics)121 }122 createDiagnostics(parser.ValidateConcepts(conceptDictionary), diagnostics)123 return conceptDictionary, nil124}125func createDiagnostics(res *parser.ParseResult, diagnostics map[lsp.DocumentURI][]lsp.Diagnostic) {126 for _, err := range res.ParseErrors {127 uri := util.ConvertPathToURI(err.FileName)128 diagnostics[uri] = append(diagnostics[uri], createDiagnostic(uri, err.Message, err.LineNo-1, err.SpanEnd-1, 1))129 }130 for _, warning := range res.Warnings {131 uri := util.ConvertPathToURI(warning.FileName)132 diagnostics[uri] = append(diagnostics[uri], createDiagnostic(uri, warning.Message, warning.LineNo-1, warning.LineSpanEnd-1, 2))133 }134}135func createDiagnostic(uri lsp.DocumentURI, message string, line int, lineEnd int, severity lsp.DiagnosticSeverity) lsp.Diagnostic {136 endChar := 10000137 if isOpen(uri) {138 endChar = len(getLine(uri, line))139 }140 return lsp.Diagnostic{141 Range: lsp.Range{142 Start: lsp.Position{Line: line, Character: 0},143 End: lsp.Position{Line: lineEnd, Character: endChar},144 },145 Message: message,146 Severity: severity,147 }148}149func getContentFromFileOrDisk(fileName string) (string, error) {150 uri := util.ConvertPathToURI(fileName)151 if isOpen(uri) {152 return getContent(uri), nil153 } else {154 return common.ReadFileContents(fileName)155 }156}...
diagnostics_test.go
Source:diagnostics_test.go
...23 os.Exit(exitCode)24}25func setup() {26 openFilesCache = &files{cache: make(map[lsp.DocumentURI][]string)}27 openFilesCache.add(util.ConvertPathToURI(conceptFile), "")28 openFilesCache.add(util.ConvertPathToURI(specFile), "")29 responses := map[gauge_messages.Message_MessageType]interface{}{}30 responses[gauge_messages.Message_StepValidateResponse] = &gauge_messages.StepValidateResponse{IsValid: true}31 lRunner.runner = &runner.GrpcRunner{LegacyClient: &mockClient{responses: responses}, Timeout: time.Second * 30}32 util.GetConceptFiles = func() []string {33 return []string{conceptFile}34 }35 util.GetSpecFiles = func(paths []string) []string {36 return []string{specFile}37 }38}39func tearDown() {40 lRunner.runner = nil41}42func TestDiagnosticWithParseErrorsInSpec(t *testing.T) {43 setup()44 specText := `Specification Heading45=====================46Scenario Heading47================48* Step text`49 uri := util.ConvertPathToURI(specFile)50 openFilesCache.add(uri, specText)51 want := []lsp.Diagnostic{52 {53 Range: lsp.Range{54 Start: lsp.Position{Line: 0, Character: 0},55 End: lsp.Position{Line: 1, Character: 21},56 },57 Message: "Spec should have atleast one scenario",58 Severity: 1,59 },60 {61 Range: lsp.Range{62 Start: lsp.Position{Line: 3, Character: 0},63 End: lsp.Position{Line: 4, Character: 16},64 },65 Message: "Multiple spec headings found in same file",66 Severity: 1,67 },68 }69 diagnostics, err := getDiagnostics()70 if err != nil {71 t.Errorf("Expected no error, got : %s", err.Error())72 }73 got := diagnostics[uri]74 if !reflect.DeepEqual(got, want) {75 t.Errorf("want: `%+v`,\n got: `%+v`", want, got)76 }77}78func TestDiagnosticWithNoErrors(t *testing.T) {79 setup()80 specText := `Specification Heading81=====================82Scenario Heading83----------------84* Step text85`86 uri := util.ConvertPathToURI(specFile)87 openFilesCache.add(uri, specText)88 d, err := getDiagnostics()89 if err != nil {90 t.Errorf("expected no error.\n Got: %s", err.Error())91 }92 if len(d[uri]) > 0 {93 t.Errorf("expected no error.\n Got: %+v", d)94 }95}96func TestParseConcept(t *testing.T) {97 setup()98 cptText := `# concept99* foo100`101 uri := util.ConvertPathToURI(conceptFile)102 openFilesCache.add(uri, cptText)103 diagnostics := make(map[lsp.DocumentURI][]lsp.Diagnostic)104 dictionary, err := validateConcepts(diagnostics)105 if err != nil {106 t.Errorf("expected no error.\n Got: %s", err.Error())107 }108 if len(dictionary.ConceptsMap) == 0 {109 t.Errorf("Concept dictionary is empty")110 }111 if len(diagnostics[uri]) > 0 {112 t.Errorf("Parsing failed, got : %+v", diagnostics)113 }114}115func TestDiagnosticsForConceptParseErrors(t *testing.T) {116 setup()117 cptText := `# concept`118 uri := util.ConvertPathToURI(conceptFile)119 openFilesCache.add(uri, cptText)120 diagnostics := make(map[lsp.DocumentURI][]lsp.Diagnostic)121 _, err := validateConcepts(diagnostics)122 if err != nil {123 t.Error(err)124 }125 if len(diagnostics[uri]) <= 0 {126 t.Errorf("expected parse errors")127 }128 want := []lsp.Diagnostic{129 {130 Range: lsp.Range{131 Start: lsp.Position{Line: 0, Character: 0},132 End: lsp.Position{Line: 0, Character: 9},133 },134 Message: "Concept should have atleast one step",135 Severity: 1,136 },137 }138 if !reflect.DeepEqual(want, diagnostics[uri]) {139 t.Errorf("want: `%v`,\n got: `%v`", want, diagnostics[uri])140 }141}142func TestDiagnosticOfConceptsWithCircularReference(t *testing.T) {143 setup()144 cptText := `# concept145* concept146`147 uri := util.ConvertPathToURI(conceptFile)148 openFilesCache.add(uri, cptText)149 diagnostics, err := getDiagnostics()150 if err != nil {151 t.Errorf("expected no error.\n Got: %s", err.Error())152 }153 got := diagnostics[uri]154 containsDiagnostics(got, 1, 0, "Circular reference found in concept.", t)155}156var containsDiagnostics = func(diagnostics []lsp.Diagnostic, line1, line2 int, startMessage string, t *testing.T) {157 for _, diagnostic := range diagnostics {158 if !strings.Contains(diagnostic.Message, startMessage) {159 t.Errorf("Invalid error message, got : %s : ", diagnostic.Message)160 }161 if (diagnostic.Range.Start.Line != line1 || diagnostic.Range.Start.Line != line2) && diagnostic.Range.Start.Character != 0 {...
ConvertPathToURI
Using AI Code Generation
1import (2func main() {3 fmt.Println(util.ConvertPathToURI("/home/abc/xyz"))4}5import (6func ConvertPathToURI(path string) string {7 return strings.Replace(path, "\\", "/", -1)8}
ConvertPathToURI
Using AI Code Generation
1import (2func main() {3 vm := otto.New()4 fileData, err := ioutil.ReadFile("util.js")5 if err != nil {6 fmt.Println("Error reading file: ", err)7 os.Exit(1)8 }9 vm.Run(fileData)10 convertPathToURI, err := vm.Get("convertPathToURI")11 value, err := convertPathToURI.Call(convertPathToURI, "C:\\Users\\srikanth\\Desktop\\test\\test.txt")12 if err != nil {13 fmt.Println("Error calling function: ", err)14 os.Exit(1)15 }16 fmt.Println(value)17}18function convertPathToURI(path) {19}
ConvertPathToURI
Using AI Code Generation
1import (2func main() {3 uri, err := util.ConvertPathToURI(path)4 if err != nil {5 fmt.Println(err)6 } else {7 fmt.Println("URI for the path is: ", uri)8 }9}
ConvertPathToURI
Using AI Code Generation
1import (2func main() {3 fmt.Println(util.ConvertPathToURI("C:/Users/abc/Desktop/test.txt"))4}5import (6func main() {7 fmt.Println(util.ConvertPathToURL("C:/Users/abc/Desktop/test.txt"))8}9import (10func main() {11 fmt.Println(util.GetAbsGlobExps("C:/Users/abc/Desktop/test.txt"))12}13import (14func main() {15 fmt.Println(util.GetAbsGlobExps("C:/Users/abc/Desktop/test.txt"))16}17import (18func main() {19 fmt.Println(util.GetAbsGlobExps("C:/Users/abc/Desktop/test.txt"))20}
ConvertPathToURI
Using AI Code Generation
1import (2func main() {3 uri, err := util.ConvertPathToURI(inputPath)4 if err != nil {5 fmt.Println(err)6 }7 fmt.Println(uri)8}
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!!