<commit_before>﻿#region License
/*********************************************************************************
 * JsonSyntaxTests.cs
 * 
 * Copyright (c) 2004-2018 <NAME>
 * 
 *    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.
 * 
 *********************************************************************************/
#endregion

using Sandra.UI.WF.Storage;
using System;
using System.Collections.Generic;
using Xunit;

namespace Sandra.UI.WF.Tests
{
    public class JsonSyntaxTests
    {
        /// <summary>
        /// For testing JsonTerminalSymbols in general.
        /// </summary>
        private class JsonTestSymbol : JsonTerminalSymbol
        {
            public override void Accept(JsonTerminalSymbolVisitor visitor) => visitor.DefaultVisit(this);
            public override TResult Accept<TResult>(JsonTerminalSymbolVisitor<TResult> visitor) => visitor.DefaultVisit(this);
        }

        [Fact]
        public void NullSymbolOrJsonShouldThrow()
        {
            Assert.Throws<ArgumentNullException>(() => new JsonTextElement(null, string.Empty, 0, 0));
            Assert.Throws<ArgumentNullException>(() => new JsonTextElement(new JsonTestSymbol(), null, 0, 0));
        }

        [Theory]
        [InlineData("", -1, 0, "start")]
        [InlineData("", -1, -1, "start")]
        [InlineData("", 0, -1, "length")]
        [InlineData("", 1, 0, "start")]
        [InlineData("", 0, 1, "length")]
        [InlineData(" ", 0, 2, "length")]
        [InlineData(" ", 1, 1, "length")]
        [InlineData(" ", 2, 0, "start")]
        public void OutOfRangeArguments(string json, int start, int length, string parameterName)
        {
            Assert.Throws<ArgumentOutOfRangeException>(parameterName, () => new JsonTextElement(new JsonTestSymbol(), json, start, length));
        }

        [Theory]
        [InlineData("", 0, 0)]
        [InlineData("{}", 0, 1)]
        // No newline conversions.
        [InlineData("\n", 1, 0)]
        [InlineData("\r\n", 0, 2)]
        public void UnchangedParameters(string json, int start, int length)
        {
            var testSymbol = new JsonTestSymbol();
            var textElement = new JsonTextElement(testSymbol, json, start, length);
            Assert.Equal(start, textElement.Start);
            Assert.Equal(length, textElement.Length);
            Assert.Same(testSymbol, textElement.TerminalSymbol);
        }

        [Fact]
        public void NullValueShouldThrow()
        {
            Assert.Throws<ArgumentNullException>(() => new JsonString(null));
            Assert.Throws<ArgumentNullException>(() => new JsonValue(null));
        }

        [Theory]
        [InlineData("")]
        [InlineData("{}")]
        // No newline conversions.
        [InlineData("\n")]<commit_msg>Remove test cases which depend on the json passed to the JsonTextElement constructor.<commit_after>﻿#region License
/*********************************************************************************
 * JsonSyntaxTests.cs
 * 
 * Copyright (c) 2004-2018 <NAME>
 * 
 *    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.
 * 
 *********************************************************************************/
#endregion

using Sandra.UI.WF.Storage;
using System;
using System.Collections.Generic;
using Xunit;

namespace Sandra.UI.WF.Tests
{
    public class JsonSyntaxTests
    {
        /// <summary>
        /// For testing JsonTerminalSymbols in general.
        /// </summary>
        private class JsonTestSymbol : JsonTerminalSymbol
        {
            public override void Accept(JsonTerminalSymbolVisitor visitor) => visitor.DefaultVisit(this);
            public override TResult Accept<TResult>(JsonTerminalSymbolVisitor<TResult> visitor) => visitor.DefaultVisit(this);
        }

        [Fact]
        public void NullSymbolShouldThrow()
        {
            Assert.Throws<ArgumentNullException>(() => new JsonTextElement(null, string.Empty, 0, 0));
        }

        [Theory]
        [InlineData(-1, 0, "start")]
        [InlineData(-1, -1, "start")]
        [InlineData(0, -1, "length")]
        public void OutOfRangeArguments(int start, int length, string parameterName)
        {
            Assert.Throws<ArgumentOutOfRangeException>(parameterName, () => new JsonTextElement(new JsonTestSymbol(), string.Empty, start, length));
        }

        [Theory]
        [InlineData(0, 0)]
        [InlineData(0, 1)]
        [InlineData(1, 0)]
        [InlineData(0, 2)]
        public void UnchangedParameters(int start, int length)
        {
            var testSymbol = new JsonTestSymbol();
            var textElement = new JsonTextElement(testSymbol, "  ", start, length);
            Assert.Equal(start, textElement.Start);
            Assert.Equal(length, textElement.Length);
            Assert.Same(testSymbol, textElement.TerminalSymbol);
        }

        [Fact]
        public void NullValueShouldThrow()
        {
            Assert.Throws<ArgumentNullException>(() => new JsonString(null));
            Assert.Throws<ArgumentNullException>(() => new JsonValue(null));
        }

        [Theory]
        [InlineData("")]
        [InlineData("{}")]
        // No newline conversions.
        [InlineData("\n")]
{'fraction_non_alphanumeric': 0.16241632132610775, 'fraction_numerical': 0.010838380618425247, 'mean_word_length': 2.72624703087886, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1868572', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1619, 'n_words': 463}