This repository was archived by the owner on Apr 5, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +50
-28
lines changed
Filter options
Expand file tree Collapse file tree 6 files changed +50
-28
lines changed
Original file line number Diff line number Diff line change @@ -85,10 +85,9 @@ module Token =
85
85
result.Close()
86
86
| n ->
87
87
let txt = input.Substring( pos+ 1 , n- pos-1 )
88
- if txt <> " " then
89
- result.Add { Text = txt
90
- Extent = extent ( pos+ 1 ) n
91
- Quotes = Quotes quote }
88
+ result.Add { Text = txt
89
+ Extent = extent ( pos+ 1 ) n
90
+ Quotes = Quotes quote }
92
91
loop input ( n+ 1 ) & result
93
92
94
93
let ofString ( input : string ) =
Original file line number Diff line number Diff line change @@ -72,14 +72,10 @@ let complete pos input =
72
72
Fargo.Run.complete p pos ( Token.ofString input)
73
73
74
74
let complete2 pos input =
75
- let w = new IO.StringWriter()
76
- Console.SetOut( w)
77
-
78
- Run.run " test" p [| " complete" ; " --position" ; string pos; input |] ( fun _ x -> printfn " %A " x; Task.FromResult 0 ) |> ignore
79
- Regex.Replace( w.ToString(), $" {'\x1b '}\[\d +m" , " " ) .Split( '\n' )
80
- |> Array.map ( fun l -> l.TrimEnd())
81
- |> Array.filter ( not << String.IsNullOrEmpty)
82
- |> String.concat Environment.NewLine
75
+ Testing.withStdout ( fun _ ->
76
+
77
+ Run.run " test" p [| " complete" ; " --position" ; string pos; input |] ( fun _ x -> task { printfn " %A " x; return 0 }) |> ignore
78
+ )
83
79
84
80
85
81
[<Fact>]
Original file line number Diff line number Diff line change 4
4
<TargetFramework >net7.0</TargetFramework >
5
5
<GenerateDocumentationFile >true</GenerateDocumentationFile >
6
6
</PropertyGroup >
7
- <ItemGroup >
8
- <Compile Include =" *.fs" />
7
+ <ItemGroup >
8
+ <Compile Include =" Testing.fs" />
9
+ <Compile Include =" Token.fs" />
10
+ <Compile Include =" Parsing.fs" />
11
+ <Compile Include =" Usage.fs" />
12
+ <Compile Include =" Completion.fs" />
13
+ <Compile Include =" AllAtOnce.fs" />
9
14
</ItemGroup >
10
15
<ItemGroup >
11
16
<ProjectReference Include =" ..\..\src\Fargo\Fargo.fsproj" />
Original file line number Diff line number Diff line change
1
+ module Testing
2
+
3
+ open System
4
+ open System.Text .RegularExpressions
5
+
6
+ let testLock = obj()
7
+
8
+ let withStdout f =
9
+ lock testLock ( fun _ ->
10
+
11
+ let w = new IO.StringWriter()
12
+ Console.SetOut( w)
13
+
14
+ f()
15
+
16
+ Regex.Replace( w.ToString(), $" {'\x1b '}\[\d +m" , " " ) .Split( '\n' )
17
+ |> Array.map ( fun l -> l.TrimEnd())
18
+ |> Array.filter ( not << String.IsNullOrEmpty)
19
+ |> String.concat Environment.NewLine
20
+ )
21
+
22
+
23
+
24
+
25
+
Original file line number Diff line number Diff line change @@ -104,3 +104,11 @@ let ``Token.ofString then Token.toString should give same result`` (NonNull (arg
104
104
let trimmed = args.TrimEnd()
105
105
let result = trimmed |> Token.ofString |> Token.toString
106
106
result =! trimmed
107
+
108
+
109
+ [<Fact>]
110
+ let ``Token.ofString then Token.toString should give same result with empty quotes `` () =
111
+ let trimmed = " \"\" "
112
+ let result = trimmed |> Token.ofString |> Token.toString
113
+ result =! trimmed
114
+
Original file line number Diff line number Diff line change @@ -12,22 +12,11 @@ let (=!) (actual:'a) (expected: 'a) = Differ.Assert(expected, actual )
12
12
13
13
let outUsage ( p , c ) input =
14
14
let _ , _ , usages = p ( Token.ofString input)
15
- let w = new IO.StringWriter()
16
- Console.SetOut( w)
17
- printHelp usages
18
- Regex.Replace( w.ToString(), $" {'\x1b '}\[\d +m" , " " ) .Split( '\n' )
19
- |> Array.map ( fun l -> l.TrimEnd())
20
- |> Array.filter ( not << String.IsNullOrEmpty)
21
- |> String.concat Environment.NewLine
15
+ Testing.withStdout( fun _ -> printHelp usages)
22
16
23
17
let outRun p input =
24
- let w = new IO.StringWriter()
25
- Console.SetOut( w)
26
- run " test" p [| input|] ( fun _ v -> printfn " %A " v; Task.FromResult 0 ) |> ignore
27
- Regex.Replace( w.ToString(), $" {'\x1b '}\[\d +m" , " " ) .Split( '\n' )
28
- |> Array.map ( fun l -> l.TrimEnd())
29
- |> Array.filter ( not << String.IsNullOrEmpty)
30
- |> String.concat Environment.NewLine
18
+ Testing.withStdout( fun _ ->
19
+ run " test" p [| input|] ( fun _ v -> task { printfn " %A " v; return 0 }) |> ignore)
31
20
32
21
[<Fact>]
33
22
let ``arg usage`` () =
You can’t perform that action at this time.
0 commit comments