@@ -17,7 +17,7 @@ import (
1717 "github.com/sourcegraph/jsonrpc2"
1818)
1919
20- func TestFormat (t * testing.T ) {
20+ func TestSpecFormat (t * testing.T ) {
2121 specText := `# Specification Heading
2222
2323## Scenario Heading
@@ -50,7 +50,7 @@ func TestFormat(t *testing.T) {
5050 }
5151}
5252
53- func TestFormatParseError (t * testing.T ) {
53+ func TestSpecFormatParseError (t * testing.T ) {
5454 specText := `Specification Heading
5555=====================
5656
@@ -67,7 +67,7 @@ func TestFormatParseError(t *testing.T) {
6767 b , _ := json .Marshal (lsp.DocumentFormattingParams {TextDocument : lsp.TextDocumentIdentifier {URI : specFile }, Options : lsp.FormattingOptions {}})
6868 p := json .RawMessage (b )
6969
70- expectedError := fmt .Errorf ("failed to format document . Fix all the problems first" )
70+ expectedError := fmt .Errorf ("failed to format foo.spec . Fix all the problems first" )
7171
7272 data , err := format (& jsonrpc2.Request {Params : & p })
7373 if data != nil {
@@ -76,5 +76,58 @@ func TestFormatParseError(t *testing.T) {
7676 if err .Error () != expectedError .Error () {
7777 t .Fatalf (" want : %s\n got : %s" , expectedError .Error (), err .Error ())
7878 }
79+ }
80+
81+ func TestConceptFormat (t * testing.T ) {
82+ conceptText := `# Concept Scenario Heading
83+
84+ * Step text`
85+
86+ openFilesCache = & files {cache : make (map [lsp.DocumentURI ][]string )}
87+ openFilesCache .add ("foo.cpt" , conceptText )
88+
89+ want := []lsp.TextEdit {
90+ {
91+ Range : lsp.Range {
92+ Start : lsp.Position {Line : 0 , Character : 0 },
93+ End : lsp.Position {Line : 3 , Character : 39 },
94+ },
95+ NewText : conceptText + "\n " ,
96+ },
97+ }
98+
99+ b , _ := json .Marshal (lsp.DocumentFormattingParams {TextDocument : lsp.TextDocumentIdentifier {URI : "foo.cpt" }, Options : lsp.FormattingOptions {}})
100+ p := json .RawMessage (b )
101+
102+ got , err := format (& jsonrpc2.Request {Params : & p })
103+ if err != nil {
104+ t .Fatalf ("Expected error == nil in format, got %s" , err .Error ())
105+ }
79106
107+ if ! reflect .DeepEqual (got , want ) {
108+ t .Errorf ("format failed, want: `%v`, got: `%v`" , want , got )
109+ }
110+ }
111+
112+ func TestConceptFormatParseError (t * testing.T ) {
113+ conceptText := `Concept Scenario Heading
114+ * Step text`
115+
116+ openFilesCache = & files {cache : make (map [lsp.DocumentURI ][]string )}
117+ openFilesCache .add ("foo.cpt" , conceptText )
118+
119+ conceptFile := lsp .DocumentURI ("foo.cpt" )
120+
121+ b , _ := json .Marshal (lsp.DocumentFormattingParams {TextDocument : lsp.TextDocumentIdentifier {URI : conceptFile }, Options : lsp.FormattingOptions {}})
122+ p := json .RawMessage (b )
123+
124+ expectedError := fmt .Errorf ("failed to format foo.cpt. Fix all the problems first" )
125+
126+ data , err := format (& jsonrpc2.Request {Params : & p })
127+ if data != nil {
128+ t .Fatalf ("Expected data == nil in format, got %s" , data )
129+ }
130+ if err .Error () != expectedError .Error () {
131+ t .Fatalf (" want : %s\n got : %s" , expectedError .Error (), err .Error ())
132+ }
80133}
0 commit comments