示例#1
0
        public void DefineConstants()
        {
            IBuildEngine2 mockEngine = new MockEngine();
            Csc           t          = new Csc();

            t.BuildEngine = mockEngine;

            // Perfectly valid, so no change expected.
            Assert.AreEqual("DEBUG;TRACE",
                            t.GetDefineConstantsSwitch("DEBUG;TRACE"));

            // Spaces should be removed.
            Assert.AreEqual("DEBUG;TRACE",
                            t.GetDefineConstantsSwitch("DEBUG; TRACE"));

            // Commas become semicolons.
            Assert.AreEqual("DEBUG;TRACE",
                            t.GetDefineConstantsSwitch("DEBUG , TRACE"));

            // We ignore anything that has quotes.
            Assert.AreEqual("DEBUG",
                            t.GetDefineConstantsSwitch("DEBUG , \"TRACE\""));

            // We ignore anything that has an equals sign.
            Assert.AreEqual("DEBUG;TRACE",
                            t.GetDefineConstantsSwitch("DEBUG,TRACE,MYDEFINE=MYVALUE"));

            // Since we split on space and comma, what seems like a value actually
            // becomes a new constant.  Yes, this is really what happens in
            // Everett VS.
            Assert.AreEqual("DEBUG;TRACE;MYDEFINE;MYVALUE",
                            t.GetDefineConstantsSwitch("DEBUG,TRACE,MYDEFINE = MYVALUE"));

            // Since we split on space and comma/semicolon, what seems like a value actually
            // becomes a new constant.  Yes, this is really what happens in
            // Everett VS.
            Assert.AreEqual("DEBUG;TRACE;MYDEFINE;MY;VALUE",
                            t.GetDefineConstantsSwitch("DEBUG,TRACE,MYDEFINE = MY VALUE"));

            // Even if the comma is inside quotes, we still split on it.  Yup, this
            // is what VS did in Everett.
            Assert.AreEqual("DEBUG;TRACE;MYDEFINE;WEIRD",
                            t.GetDefineConstantsSwitch("DEBUG,TRACE,MYDEFINE = \"MY,WEIRD,VALUE\""));

            // Once again, quotes aren't allowed.
            Assert.AreEqual("DEBUG;TRACE;MYDEFINE",
                            t.GetDefineConstantsSwitch("DEBUG,TRACE,MYDEFINE = \"MY VALUE\""));

            // (,),@,%,$ aren't allowed, and spaces are a valid delimiter.
            Assert.AreEqual("DEBUG;TRACE;a;b",
                            t.GetDefineConstantsSwitch("DEBUG;TRACE;a b;(;);@;%;$"));

            // Dash is not allowed either.  It's not a valid character in an
            // identifier.
            Assert.AreEqual("DEBUG;TRACE;MYDEFINE",
                            t.GetDefineConstantsSwitch("DEBUG,TRACE,MYDEFINE = -1"));

            // Identifiers cannot begin with numbers.
            Assert.AreEqual("DEBUG;TRACE;MYDEFINE",
                            t.GetDefineConstantsSwitch("DEBUG,TRACE,MYDEFINE;123ABC"));

            // But identifiers can contain numbers.
            Assert.AreEqual("DEBUG;TRACE;MYDEFINE;ABC123",
                            t.GetDefineConstantsSwitch("DEBUG,TRACE,MYDEFINE;ABC123"));

            // Identifiers can contain initial underscores and embedded underscores.
            Assert.AreEqual("_DEBUG;MY_DEFINE",
                            t.GetDefineConstantsSwitch("_DEBUG, MY_DEFINE"));

            // We should get back "null" if there's nothing valid in there.
            Assert.AreEqual(null,
                            t.GetDefineConstantsSwitch("DEBUG=\"myvalue\""));
        }