forked from nilproject/NiL.JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUglifyJs.cs
60 lines (52 loc) · 1.59 KB
/
UglifyJs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NiL.JS;
using NiL.JS.Core;
namespace FunctionalTests
{
[TestClass]
public class UglifyJs
{
private static readonly string UglifyJsScriptPath = Environment.CurrentDirectory + "/../../../../Tests/uglifyjs.js";
private Module _module;
private GlobalContext _context;
[TestInitialize]
public void Initialize()
{
using (var file = new FileStream(UglifyJsScriptPath, FileMode.Open))
using (var fileReader = new StreamReader(file))
{
_context = new GlobalContext();
_context.ActivateInCurrentThread();
_module = new Module(fileReader.ReadToEnd());
}
_module.Run();
}
[TestCleanup]
public void Cleanup()
{
_context.Deactivate();
}
[TestMethod]
public void UglifyJsShouldWorkCorrectly()
{
var myString =
@"(function (fallback) {
fallback = fallback || function () { };
})(null);";
_module.Context.DefineVariable("code").Assign(myString);
var result = _module.Context.Eval(
@"var ast = UglifyJS.parse(code);
ast.figure_out_scope();
compressor = UglifyJS.Compressor();
ast = ast.transform(compressor);
ast.print_to_string();");
Assert.AreEqual("!function(fallback){fallback=fallback||function(){}}(null);", result.ToString());
}
}
}