適当にver2

ねむい

フォーマット関連のテストを大量に書くのが面倒なのでジェネーレタ的なものを作成してみた

Jasmineがナイスなフレームワークなのは確かなわけだが

似たようなテストを延々書くのは疲れる上に保守観点上もよろしくないので

外部テストケースからのジェネレータ的なものを組んでみた。

かなり適当に書いたけど基本はこんな感じでいいはず。多分。

 public static void Main(string[] args)
        {
            string readerPath = args[0];
            string writerPath = args[1];

            using (StreamWriter wStream = new StreamWriter(writerPath))
            {
                using (StreamReader rStream = new StreamReader(readerPath))
                {
                    //header 
                    wStream.WriteLine(@"/// <reference path='./helpers.js' />");//テストしたいJSファイルのパス

                    int rStreamCounter = 0;

                    while (rStream.Peek() > 0)
                    {
                        rStreamCounter++;
                        //読み取るデータのフォーマットは特定の形式のCSVファイル
                        //data[0] フォーマットID(文字列)
                        //data[1] テストのカテゴリ。"Format"か"Parse"のどちらか
                        //data[2] 入力値。文字列の場合には''で括った値、数値の場合は値を直接、日時の場合は[new Date()]とかJavaScriptの認識する形式を直接書く。
                        //data[3] 結果値。文字列の場合には''で括った値、数値の場合は値を直接、日時の場合は[new Date()]とかJavaScriptの認識する形式を直接書く。
                        string[] data = rStream.ReadLine().Split(',');
                        string formatId = data[0];
                        string testCategory = data[1];
                        string inputText = data[2];
                        string expectText = data[3];

                        string testCaseMessage = "TestCase:" + rStreamCounter + " ID:" + formatId + " Type:" + testCategory;
                        string subCaseMessage = " Input:" + inputText + " Expect:" + expectText;//このままだと数値の場合以外はエスケープの仕方とかがまずいので、一段変換が必要な感じ

                        wStream.WriteLine("describe('" + testCaseMessage + "', function () {");
                        wStream.WriteLine("var actualValue,inputValue,expectValue;");
                        wStream.WriteLine("it('" + subCaseMessage + "', function () {");
                        wStream.WriteLine("inputValue = " + inputText + ";");
                        wStream.WriteLine("expectValue = " + expectText + ";");

                        wStream.WriteLine("actualValue =helpers." + testCategory.ToLowerInvariant() + "(" + formatId + ",inputValue);");
                        wStream.WriteLine("expect(expectValue).toEqual(actualValue);");
                        wStream.WriteLine(" });");
                        wStream.WriteLine(" });");
                    }
                }
            }
        }