Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / JSGeneration / JSCodeGeneratorTestCase.cs
blob591cb325f6e426834bee3bd3d06a49e879abd18d
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Tests.JSGeneration
17 using Castle.MonoRail.Framework.JSGeneration;
18 using NUnit.Framework;
20 [TestFixture]
21 public class JSCodeGeneratorTestCase
23 private JSCodeGenerator codeGen;
25 [SetUp]
26 public void Init()
28 codeGen = new JSCodeGenerator();
31 [Test]
32 public void Call_CorrectlyRecordsFunctionCall()
34 codeGen.Call("alert", "'hey'");
36 Assert.AreEqual("alert('hey');\r\n", codeGen.Lines.ToString());
39 [Test]
40 public void Call_CorrectlyRecordsFunctionCallsInARow()
42 codeGen.Call("alert", "'hey'");
43 codeGen.Call("window.href.change");
44 codeGen.Call("math.sum", 1, 2);
46 Assert.AreEqual("alert('hey');\r\nwindow.href.change();\r\nmath.sum(1,2);\r\n", codeGen.Lines.ToString());
49 [Test]
50 public void Write_JustTransferContentToBuffer()
52 codeGen.Write("something");
54 Assert.AreEqual("something", codeGen.Lines.ToString());
57 [Test]
58 public void Record_JustTransferContentToBufferWithNewLine()
60 codeGen.AppendLine("something");
62 Assert.AreEqual("something;\r\n", codeGen.Lines.ToString());
65 [Test]
66 public void AppendLine_JustTransferContentToBufferWithNewLine()
68 codeGen.AppendLine("something");
70 Assert.AreEqual("something;\r\n", codeGen.Lines.ToString());
73 [Test]
74 public void ReplaceTailByPeriod_FixesTheContentCorrectly()
76 codeGen.AppendLine("something");
77 codeGen.ReplaceTailByPeriod();
79 Assert.AreEqual("something.", codeGen.Lines.ToString());
82 [Test]
83 public void ReplaceTailByPeriod_IgnoresEmptyBuffer()
85 codeGen.ReplaceTailByPeriod();
87 Assert.AreEqual("", codeGen.Lines.ToString());
90 [Test]
91 public void RemoveTail_FixesTheContentCorrectly()
93 codeGen.AppendLine("something");
94 codeGen.RemoveTail();
96 Assert.AreEqual("something", codeGen.Lines.ToString());
99 [Test]
100 public void GenerateFinalJsCode_CanGenerateEmptyCall()
102 string expected = "try \n{\n}\ncatch(e)\n{\n" +
103 "alert('JS error ' + e.toString());\n" +
104 "}";
106 Assert.AreEqual(expected, codeGen.GenerateFinalJsCode());