
'test VBSArguments.vbs

With CreateObject("includer")
    Execute .read("VBSArguments")
    Execute .read("TestingFramework")
    Execute .read("TextStreamer")
End With
Dim a : Set a = New VBSArguments
Dim ts : Set ts = New TextStreamer
Dim sh : Set sh = CreateObject("WScript.Shell")

With New TestingFramework

    .describe "VBSArguments class"

        'generate a script that will call the class
        'under test and send the results to StdOut
        Dim script : script = ts.GetFile & ".vbs"
        ts.SetFile script
        Dim stream : Set stream = ts.Open
        stream.WriteLine "'Autogenerated script: writes command-line arguments to StdOut"
        stream.WriteLine "With CreateObject(""includer"")"
        stream.WriteLine "    Execute(.read(""VBSArguments""))"
        stream.WriteLine "End With"
        stream.WriteLine "With New VBSArguments"
        stream.WriteLine "    WScript.StdOut.WriteLine .GetArgumentsString"
        stream.WriteLine "End With"
        stream.Close

        Dim arg, args
        Dim pipe

    .it "should get a string of command-line arguments with spaces"
        args = """Some File.txt"" ""Some File2.txt"""
        Set pipe = sh.Exec("%ComSpec% /c cscript //nologo " & script & " " & args)
        .AssertEqual pipe.StdOut.ReadLine, " " & args

    .it "should get a single command-line argument with spaces"
        arg = """Some File.txt"""
        Set pipe = sh.Exec("%ComSpec% /c cscript //nologo " & script & " " & arg)
        .AssertEqual pipe.StdOut.ReadLine, " " & arg

    .it "should get a single command-line argument without spaces"
        arg = """SomeFile.txt"""
        Set pipe = sh.Exec("%ComSpec% /c cscript //nologo " & script & " " & arg)
        .AssertEqual pipe.StdOut.ReadLine, " " & arg

    .it "should get a single command-line argument without spaces #2"

        'Note: VBSArguments.GetArgumentsString wraps each argument
        'in double quotes, regardless of whether it contains spaces
        arg = "SomeFile.txt"
        Set pipe = sh.Exec("%ComSpec% /c cscript //nologo " & script & " " & arg)
        .AssertEqual pipe.StdOut.ReadLine, " """ & arg & """"

    'cleanup
    Set pipe = Nothing 'release object memory
    Set sh = Nothing
    ts.Delete 'delete the test script

End With
