public static Argument Option(string name, string value) { return(new Argument(name, new CommandLineValue(ArgumentValue.FromString(value)))); }
public static IEnumerable <object[]> GetTestArgumentProcessingTestCases() { // Current method return 'test case' information that contains two arguments for TestArgumentProcessing method: // literal to parse and factory method that will return an argument. // This factory can't return Argument instance because to create an instance FrontEndContextCore is required. // But front end context is test-specific and belong to the current instance. // // Scalar + primitive value test cases // yield return(TestCase( @"export const x = {name: ""foo"", value: 42};", (context) => Cmd.Option("foo", 42))); yield return(TestCase( @"export const x = {name: ""foo"", value: ""42""};", (context) => Cmd.Option("foo", "42"))); yield return(TestCase( @"export const x = {name: undefined, value: ""42""};", (context) => Cmd.Option(null, "42"))); yield return(TestCase( @"export const x = {value: ""42""};", (context) => Cmd.Argument("42"))); // // Scalar + FileArtifact test cases // yield return(TestCase( WrapWithArtifactKind(String.Format(@"export const x = {{name: ""scalar1"", value: {{kind: ArtifactKind.output, path: p`{0}foo.cs`}}}};", m_testAbsolutePath)), (context) => Cmd.Option("scalar1", Artifacts.Output(CreateAbsolutePath(context, String.Format("{0}foo.cs", m_testAbsolutePath)))))); yield return(TestCase( WrapWithArtifactKind(String.Format(@"export const x = {{name: ""scalar2"", value: {{kind: ArtifactKind.input, path: p`{0}foo`}}}};", m_testAbsolutePath)), (context) => Cmd.Option("scalar2", Artifacts.Input(CreateAbsolutePath(context, String.Format("{0}foo", m_testAbsolutePath)))))); // // PrimitiveArgument test cases // yield return(TestCase( WrapWithArgumentKind(@"export const x = {name: ""prim1"", value: {kind: ArgumentKind.rawText, value: ""text""}};"), (context) => Cmd.RawText("prim1", "text"))); yield return(TestCase( WrapWithArgumentKind(@"export const x = {name: ""prim2"", value: {kind: ArgumentKind.regular, value: 42}};"), (context) => Cmd.RegularOption("prim2", 42))); yield return(TestCase( WrapWithArgumentKind(@"export const x = {name: undefined, value: {kind: ArgumentKind.startUsingResponseFile, value: undefined}};"), (context) => Cmd.StartUsingResponseFile())); yield return(TestCase( WrapWithArgumentKind(@"export const x = {name: ""@"", value: {kind: ArgumentKind.startUsingResponseFile, value: ""true""}};"), (context) => Cmd.StartUsingResponseFile("@", true))); yield return(TestCase( WrapWithArgumentKind(@"export const x = {name: ""prim4"", value: {kind: ArgumentKind.flag, value: undefined}};"), (context) => Cmd.Flag("prim4"))); // // ScalarArgument[] test cases // yield return(TestCase( WrapWithArgumentKind(@"export const x = {name: ""array1"", value: [42, ""42"", {kind: ArgumentKind.regular, value: 42}]};"), (context) => Cmd.Options( "array1", ArgumentValue.FromNumber(42), ArgumentValue.FromString("42"), ArgumentValue.FromPrimitive(ArgumentKind.Regular, new PrimitiveValue(42))))); yield return(TestCase( WrapWithArtifactKind(String.Format(@"export const x = {{name: ""array2"", value: [{{kind: ArtifactKind.output, path: p`{0}foo.cs`}}]}};", m_testAbsolutePath)), (context) => Cmd.Options( "array2", Artifacts.Output(CreateAbsolutePath(context, String.Format("{0}foo.cs", m_testAbsolutePath)))))); // // ListArgument test cases // yield return(TestCase( WrapWithArgumentKind(@"export const x = {name: ""list2"", value: {separator: "","", values: []}};"), (context) => Cmd.Option("list2", Cmd.Join(",", new ArgumentValue[0])))); yield return(TestCase( WrapWithArgumentKind(@"export const x = {name: ""list3"", value: {separator: "","", values: [1, 2, ""42""]}};"), (context) => Cmd.Option( "list3", Cmd.Join( ",", new[] { ArgumentValue.FromNumber(1), ArgumentValue.FromNumber(2), ArgumentValue.FromString("42") })))); yield return(TestCase( WrapWithArtifactKindAndArgumentKind( String.Format(@"export const x = {{name: ""list4"", value: {{separator: "","", values: [1, {{kind: ArtifactKind.output, path: p`{0}foo.cs`}}]}}}};", m_testAbsolutePath)), (context) => Cmd.Option( "list4", Cmd.Join( ",", new[] { ArgumentValue.FromNumber(1), ArgumentValue.FromAbsolutePath(ArtifactKind.Output, CreateAbsolutePath(context, String.Format("{0}foo.cs", m_testAbsolutePath))) })))); }