<commit_before>﻿using System.Linq;
using NUnit.Framework;

namespace Mond.Tests.Expressions
{
    [TestFixture]
    public class SequenceTests
    {
        [Test]
        public void Sequence()
        {
            MondState state;
            var result = Script.Run(out state, @"
                var test = seq () {
                    for (var i = 1; i <= 10; i++) {
                        if (i > 5)
                            yield break;
                        
                        yield i;
                    }
                };

                return test();
            ");
            
            var expected = new MondValue[]
            {
                1, 2, 3, 4, 5
            };

            Assert.True(result.IsEnumerable);
            Assert.True(result.Enumerate(state).Take(expected.Length).SequenceEqual(expected));
        }

        [Test]
        public void SequenceErrors()
        {
            Assert.Throws<MondCompilerException>(() => Script.Run(@"
                seq test() {
                    return;
                }
            "), "can't use return in seq");

            Assert.Throws<MondCompilerException>(() => Script.Run(@"
                fun test() {<commit_msg>Add test case for seq scopes<commit_after>﻿using System.Linq;
using NUnit.Framework;

namespace Mond.Tests.Expressions
{
    [TestFixture]
    public class SequenceTests
    {
        [Test]
        public void Sequence()
        {
            MondState state;
            var result = Script.Run(out state, @"
                var test = seq () {
                    for (var i = 1; i <= 10; i++) {
                        if (i > 5)
                            yield break;
                        
                        yield i;
                    }
                };

                return test();
            ");
            
            var expected = new MondValue[]
            {
                1, 2, 3, 4, 5
            };

            Assert.True(result.IsEnumerable);
            Assert.True(result.Enumerate(state).Take(expected.Length).SequenceEqual(expected));
        }

        [Test]
        public void SequenceScope()
        {
            MondState state;
            var result = Script.Run(out state, @"
                seq scope() {
                    {
                        var a = 10;
                        yield a;
                    }

                    {
                        var a;
                        yield a;
                    }
                }

                return scope();
            ");

            var expected = new[]
            {
                10, MondValue.Undefined
            };

            Assert.True(result.IsEnumerable);
            Assert.True(result.Enumerate(state).SequenceEqual(expected));
        }

        [Test]
        public void SequenceErrors()
        {
            Assert.Throws<MondCompilerException>(() => Script.Run(@"
                seq test() {
                    return;
                }
            "), "can't use return in seq");

            Assert.Throws<MondCompilerException>(() => Script.Run(@"
                fun test() {
{'fraction_non_alphanumeric': 0.09914475768134305, 'fraction_numerical': 0.006968641114982578, 'mean_word_length': 0.9362354383813611, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3091092', 'n_tokens_mistral': 805, 'n_tokens_neox': 724, 'n_words': 171}