forked from jetheredge/SquishIt
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding preprocessor support for arbitrary content (continue jetheredg…
- Loading branch information
Showing
8 changed files
with
227 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using SquishIt.CoffeeScript; | ||
using SquishIt.CoffeeScript.Coffee; | ||
using SquishIt.Framework; | ||
using SquishIt.Framework.Files; | ||
using SquishIt.Framework.Utilities; | ||
using SquishIt.Tests.Helpers; | ||
|
||
namespace SquishIt.Tests | ||
{ | ||
[TestFixture] | ||
public class CoffeeScriptTests | ||
{ | ||
//TODO: should probably have more tests here | ||
private JavaScriptBundleFactory javaScriptBundleFactory; | ||
private IHasher hasher; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
javaScriptBundleFactory = new JavaScriptBundleFactory(); | ||
var retryableFileOpener = new RetryableFileOpener(); | ||
hasher = new Hasher(retryableFileOpener); | ||
} | ||
|
||
[Test] | ||
public void CanBundleJavascriptWithArbitraryCoffeeScript() | ||
{ | ||
var coffee = "alert 'test' "; | ||
|
||
var tag = javaScriptBundleFactory | ||
.WithDebuggingEnabled(false) | ||
.Create() | ||
.WithPreprocessor(new CoffeeScriptPreprocessor()) | ||
.AddString(coffee, ".coffee") | ||
.Render("~/brewed.js"); | ||
|
||
var compiled = javaScriptBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"brewed.js")]; | ||
|
||
Assert.AreEqual(@"(function(){alert(""test"")}).call(this)", compiled); | ||
Assert.AreEqual(@"<script type=""text/javascript"" src=""brewed.js?r=hash""></script>", tag); | ||
} | ||
} | ||
|
||
[TestFixture] | ||
public class CoffeescriptCompilerTests | ||
{ | ||
[Test, Platform(Exclude = "Unix, Linux, Mono")] | ||
public void CompileWithSimpleAlertSucceeds() | ||
{ | ||
var compiler = new CoffeeScriptCompiler(); | ||
|
||
string result = compiler.Compile("alert 'test' "); | ||
|
||
Assert.AreEqual("(function() {\n alert('test');\n}).call(this);\n", result); | ||
} | ||
|
||
[Test, Platform(Exclude = "Unix, Linux, Mono")] | ||
public void CompileWithComplexScriptSucceeds() | ||
{ | ||
string source = @"# Assignment: | ||
number = 42 | ||
opposite = true | ||
# Conditions: | ||
number = -42 if opposite | ||
# Functions: | ||
square = (x) -> x * x | ||
# Arrays: | ||
list = [1, 2, 3, 4, 5] | ||
# Objects: | ||
math = | ||
root: Math.sqrt | ||
square: square | ||
cube: (x) -> x * square x | ||
# Splats: | ||
race = (winner, runners...) -> | ||
print winner, runners | ||
# Existence: | ||
alert 'I knew it!' if elvis?"; | ||
|
||
var compiler = new CoffeeScriptCompiler(); | ||
string result = compiler.Compile(source); | ||
} | ||
|
||
[Test, Platform(Include = "Unix, Linux, Mono")] | ||
public void CompileFailsGracefullyOnMono() | ||
{ | ||
var compiler = new CoffeeScriptCompiler(); | ||
var exception = Assert.Throws(typeof(NotSupportedException), () => compiler.Compile("")); | ||
Assert.AreEqual("Coffeescript not yet supported for mono.", exception.Message); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.