@@ -275,3 +275,128 @@ type FToolUnitTests() =
275275
276276 Assert.That( ecMissing, Is.EqualTo( 1 ))
277277 Assert.That( errMissing.Contains( " Error:" ), Is.True)
278+
279+ [<Test>]
280+ member _. ``-- chars option counts characters`` () =
281+ let tmp = Path.Combine( Path.GetTempPath(), " f_chars_" + Guid.NewGuid() .ToString( " N" ))
282+ Directory.CreateDirectory( tmp) |> ignore
283+
284+ try
285+ let testFile = Path.Combine( tmp, " test.txt" )
286+ let content = " Hello World!\n Test 123"
287+ File.WriteAllText( testFile, content)
288+
289+ let repoRoot =
290+ let rec findUp ( startDir : string ) ( marker : string ) =
291+ let full = Path.GetFullPath( startDir)
292+ let candidate = Path.Combine( full, marker)
293+ if File.Exists( candidate) then
294+ full
295+ else
296+ let parent = Directory.GetParent( full)
297+ if isNull parent then
298+ failwithf $" Could not locate '%s {marker}' above '%s {startDir}'"
299+ else
300+ findUp parent.FullName marker
301+ findUp AppContext.BaseDirectory " ancpdevkit.sln"
302+
303+ let proj = Path.Combine( repoRoot, " tools" , " ancp" , " f" , " f.fsproj" )
304+ let psi = ProcessStartInfo( " dotnet" , $" run --no-build --project {proj} --framework net9.0 -- --chars {testFile}" )
305+ psi.WorkingDirectory <- repoRoot
306+ psi.RedirectStandardOutput <- true
307+ psi.RedirectStandardError <- true
308+ use p = Process.Start( psi)
309+ let output = p.StandardOutput.ReadToEnd()
310+ p.WaitForExit()
311+
312+ Assert.That( p.ExitCode, Is.EqualTo( 0 ))
313+ Assert.That( output.Trim(), Is.EqualTo( content.Length.ToString()))
314+ finally
315+ try Directory.Delete( tmp, true ) with _ -> ()
316+
317+ [<Test>]
318+ member _. ``-- lines option counts lines`` () =
319+ let tmp = Path.Combine( Path.GetTempPath(), " f_lines_" + Guid.NewGuid() .ToString( " N" ))
320+ Directory.CreateDirectory( tmp) |> ignore
321+
322+ try
323+ let testFile = Path.Combine( tmp, " test.txt" )
324+ let content = " Line 1\n Line 2\n Line 3"
325+ File.WriteAllText( testFile, content)
326+
327+ let repoRoot =
328+ let rec findUp ( startDir : string ) ( marker : string ) =
329+ let full = Path.GetFullPath( startDir)
330+ let candidate = Path.Combine( full, marker)
331+ if File.Exists( candidate) then
332+ full
333+ else
334+ let parent = Directory.GetParent( full)
335+ if isNull parent then
336+ failwithf $" Could not locate '%s {marker}' above '%s {startDir}'"
337+ else
338+ findUp parent.FullName marker
339+ findUp AppContext.BaseDirectory " ancpdevkit.sln"
340+
341+ let proj = Path.Combine( repoRoot, " tools" , " ancp" , " f" , " f.fsproj" )
342+ let psi = ProcessStartInfo( " dotnet" , $" run --no-build --project {proj} --framework net9.0 -- --lines {testFile}" )
343+ psi.WorkingDirectory <- repoRoot
344+ psi.RedirectStandardOutput <- true
345+ psi.RedirectStandardError <- true
346+ use p = Process.Start( psi)
347+ let output = p.StandardOutput.ReadToEnd()
348+ p.WaitForExit()
349+
350+ Assert.That( p.ExitCode, Is.EqualTo( 0 ))
351+ Assert.That( output.Trim(), Is.EqualTo( " 3" ))
352+ finally
353+ try Directory.Delete( tmp, true ) with _ -> ()
354+
355+ [<Test>]
356+ member _. ``-- no - numbers option excludes numeric words`` () =
357+ let tmp = Path.Combine( Path.GetTempPath(), " f_no_nums_" + Guid.NewGuid() .ToString( " N" ))
358+ Directory.CreateDirectory( tmp) |> ignore
359+
360+ try
361+ let testFile = Path.Combine( tmp, " test.txt" )
362+ let content = " Hello 123 World 456 Test"
363+ File.WriteAllText( testFile, content)
364+
365+ let repoRoot =
366+ let rec findUp ( startDir : string ) ( marker : string ) =
367+ let full = Path.GetFullPath( startDir)
368+ let candidate = Path.Combine( full, marker)
369+ if File.Exists( candidate) then
370+ full
371+ else
372+ let parent = Directory.GetParent( full)
373+ if isNull parent then
374+ failwithf $" Could not locate '%s {marker}' above '%s {startDir}'"
375+ else
376+ findUp parent.FullName marker
377+ findUp AppContext.BaseDirectory " ancpdevkit.sln"
378+
379+ let proj = Path.Combine( repoRoot, " tools" , " ancp" , " f" , " f.fsproj" )
380+
381+ let psi1 = ProcessStartInfo( " dotnet" , $" run --no-build --project {proj} --framework net9.0 -- {testFile}" )
382+ psi1.WorkingDirectory <- repoRoot
383+ psi1.RedirectStandardOutput <- true
384+ psi1.RedirectStandardError <- true
385+ use p1 = Process.Start( psi1)
386+ let output1 = p1.StandardOutput.ReadToEnd()
387+ p1.WaitForExit()
388+
389+ let psi2 = ProcessStartInfo( " dotnet" , $" run --no-build --project {proj} --framework net9.0 -- --no-numbers {testFile}" )
390+ psi2.WorkingDirectory <- repoRoot
391+ psi2.RedirectStandardOutput <- true
392+ psi2.RedirectStandardError <- true
393+ use p2 = Process.Start( psi2)
394+ let output2 = p2.StandardOutput.ReadToEnd()
395+ p2.WaitForExit()
396+
397+ Assert.That( p1.ExitCode, Is.EqualTo( 0 ))
398+ Assert.That( p2.ExitCode, Is.EqualTo( 0 ))
399+ Assert.That( output1.Trim(), Is.EqualTo( " 5" ))
400+ Assert.That( output2.Trim(), Is.EqualTo( " 3" ))
401+ finally
402+ try Directory.Delete( tmp, true ) with _ -> ()
0 commit comments