zaaReloaded2/Tests/LineParserTest.cs

74 lines
2.2 KiB
C#
Raw Permalink Normal View History

2015-06-20 19:13:55 +00:00
/* UnitTest1.cs
* part of zaaReloaded2
*
* Copyright 2015 Daniel Kraus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using NUnit.Framework;
using zaaReloaded2.Thesaurus;
2015-06-20 19:13:55 +00:00
namespace Tests
{
[TestFixture]
class LineParserTest
{
[Test]
public void ParseSimpleLine()
{
LineParser lp = new LineParser();
lp.Line = "this is a simple line";
Assert.AreEqual("this", lp.Fields[0]);
Assert.AreEqual("simple", lp.Fields[3]);
}
[Test]
public void ParseSimpleLineWithComment()
{
LineParser lp = new LineParser();
lp.Line = "this is a simple line # with a comment";
Assert.AreEqual("this", lp.Fields[0]);
Assert.AreEqual("simple", lp.Fields[3]);
Assert.AreEqual(5, lp.Fields.Length);
}
[Test]
public void ParseLineWithQuotes()
{
LineParser lp = new LineParser();
lp.Line = "this \"is a\" simple line";
Assert.AreEqual("simple", lp.Fields[2]);
Assert.AreEqual("line", lp.Fields[3]);
}
[Test]
public void ParseLineWithQuotesAndPunctuation()
{
2015-06-21 04:12:30 +00:00
LineParser lp = new LineParser("this-is \"a , simple ;\" line");
2015-06-20 19:13:55 +00:00
Assert.AreEqual("this-is", lp.Fields[0]);
Assert.AreEqual("a , simple ;", lp.Fields[1]);
Assert.AreEqual("line", lp.Fields[2]);
}
2015-06-21 04:15:27 +00:00
[Test]
public void ParseLineWithoutFields()
{
LineParser lp = new LineParser("# no fields");
Assert.IsFalse(lp.HasFields);
lp.Line = "two fields";
Assert.IsTrue(lp.HasFields);
}
2015-06-20 19:13:55 +00:00
}
}