Upsilon/UpsilonTests/GeneralTests/StringTests.cs

55 lines
1.5 KiB
C#
Raw Normal View History

2018-11-19 12:53:44 +00:00
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
{
2018-11-23 11:55:28 +00:00
public class StringTests : TestClass
2018-11-19 12:53:44 +00:00
{
2018-11-23 11:55:28 +00:00
public StringTests(StaticScriptFixture fix) : base(fix)
{
}
2018-11-19 12:53:44 +00:00
[Fact]
public void BasicStringVariable()
{
const string input = @"
string = ""test""
return string
";
2018-11-23 11:55:28 +00:00
var script = new Script(input, BoundScope, StaticScope);
2018-11-19 12:53:44 +00:00
Assert.Empty(script.Diagnostics.Messages);
var evaluated = script.Evaluate<string>();
Assert.Empty(script.Diagnostics.Messages);
Assert.Equal("test", evaluated);
}
[Fact]
public void StringIndexable()
{
const string input = @"
string = ""test""
return string[3]
";
2018-11-23 11:55:28 +00:00
var script = new Script(input, BoundScope, StaticScope);
2018-11-19 12:53:44 +00:00
Assert.Empty(script.Diagnostics.Messages);
var evaluated = script.Evaluate<string>();
Assert.Empty(script.Diagnostics.Messages);
Assert.Equal("s", evaluated);
}
[Fact]
public void StringAddition()
{
const string input = @"
string = ""test"" + ""123""
return string
";
2018-11-23 11:55:28 +00:00
var script = new Script(input, BoundScope, StaticScope);
2018-11-19 12:53:44 +00:00
Assert.Empty(script.Diagnostics.Messages);
var evaluated = script.Evaluate<string>();
Assert.Empty(script.Diagnostics.Messages);
Assert.Equal("test123", evaluated);
}
}
}