<commit_before>﻿#region Using Directives

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

using NUnit.Framework;

using Pharmatechnik.Nav.Language;

#endregion

namespace Nav.Language.Tests {

    [TestFixture]
    public class DiagnosticTests {

        // TODO Nav0202SpontaneousOnlyAllowedAfterViewAndInitNodes
        // TODO Nav0221OnlyIfConditionsAllowedInExitTransitions
        // TODO Nav2000IdentifierExpected

        [Test]
        public void Nav0003SourceFileNeedsToBeSavedBeforeIncludeDirectiveCanBeProcessed() {

            var nav = @"
            taskref ""foo.nav""
//                   ^-------^ Nav0003SourceFileNeedsToBeSavedBeforeIncludeDirectiveCanBeProcessed
            task A
            {
                init I1;            
                exit e1;
                I1 --> e1;     
            }
            ";

            var unit = BuildCodeGenerationUnit(nav);

            ExpectExactly(unit, This(DiagnosticDescriptors.Semantic.Nav0003SourceFileNeedsToBeSavedBeforeIncludeDirectiveCanBeProcessed));
        }

        [Test]
        public void Nav0004File0NotFound() {

            var nav = @"
            taskref ""foo.nav""
//                   ^-------^ Nav0004File0NotFound
            task A
            {
                init I1;            
                exit e1;
                I1 --> e1;     
            }
            ";

            var unit = BuildCodeGenerationUnit(nav, MkFileName("bar.nav"));

            ExpectExactly(unit, This(DiagnosticDescriptors.Semantic.Nav0004File0NotFound));
        }

        [Test]
        public void Nav0005IncludeFile0HasSomeErrors() {

            var includedNav = @"           
            task A
            {
                init I1;            
                exit e1;
                I1 ---> e1; // <== SyntaxFehler
            }
            ";

            var testNav = @"          
            taskref ""includedNav.nav"";
            task B
            {
                init I1;            
                exit e1;
                task A;
                I1 --> A; 
                A:e1 --> e1;
            }
            ";

            var unit = BuildCodeGenerationUnit(new TestCaseFile {Content = testNav, FilePath     = MkFileName(nameof(testNav))},
                                               new TestCaseFile {Content = includedNav, FilePath = MkFileName(nameof(includedNav))});

            ExpectExactly(unit, This(DiagnosticDescriptors.Semantic.Nav0005IncludeFile0HasSomeErrors));
        }

        [Test]
        [Ignore("Dieser Test funktioniert in der Praxis nicht, da er bereits zu einem Syntaxfehler führt.")]
        public void Nav0102EndNodeMustNotContainLeavingEdges() {

            var nav = @"
          
            task A
            {
                init I1;            
                exit e1;
                end;
                
                I1 --> e1;
                end --> e1;
            }
            ";<commit_msg>Code Cleanup<commit_after>﻿#region Using Directives

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

using NUnit.Framework;

using Pharmatechnik.Nav.Language;

#endregion

namespace Nav.Language.Tests {

    [TestFixture]
    public class DiagnosticTests {

        // TODO Nav0202SpontaneousOnlyAllowedAfterViewAndInitNodes
        // TODO Nav2000IdentifierExpected

        [Test]
        public void Nav0003SourceFileNeedsToBeSavedBeforeIncludeDirectiveCanBeProcessed() {

            var nav = @"
            taskref ""foo.nav""
            //        ^------^ Nav0003SourceFileNeedsToBeSavedBeforeIncludeDirectiveCanBeProcessed
            task A
            {
                init I1;            
                exit e1;
                I1 --> e1;     
            }
            ";

            var unit = BuildCodeGenerationUnit(nav);

            ExpectExactly(unit, This(DiagnosticDescriptors.Semantic.Nav0003SourceFileNeedsToBeSavedBeforeIncludeDirectiveCanBeProcessed));
        }

        [Test]
        public void Nav0004File0NotFound() {

            var nav = @"
            taskref ""foo.nav""
            /         ^------^ Nav0004File0NotFound
            task A
            {
                init I1;            
                exit e1;
                I1 --> e1;     
            }
            ";

            var unit = BuildCodeGenerationUnit(nav, MkFileName("bar.nav"));

            ExpectExactly(unit, This(DiagnosticDescriptors.Semantic.Nav0004File0NotFound));
        }

        [Test]
        public void Nav0005IncludeFile0HasSomeErrors() {

            var includedNav = @"           
            task A
            {
                init I1;            
                exit e1;
                I1 ---> e1; // 
                //-^- Syntaxfehler
            }
            ";

            var testNav = @"          
            taskref ""includedNav.nav"";
            task B
            {
                init I1;            
                exit e1;
                task A;
                I1   --> A; 
                A:e1 --> e1;
            }
            ";

            var unit = BuildCodeGenerationUnit(new TestCaseFile {Content = testNav, FilePath     = MkFileName(nameof(testNav))},
                                               new TestCaseFile {Content = includedNav, FilePath = MkFileName(nameof(includedNav))});

            ExpectExactly(unit, This(DiagnosticDescriptors.Semantic.Nav0005IncludeFile0HasSomeErrors));
        }

        [Test]
        [Ignore("Dieser Test funktioniert in der Praxis nicht, da er bereits zu einem Syntaxfehler führt.")]
        public void Nav0102EndNodeMustNotContainLeavingEdges() {

            var nav = @"
          
            task A
            {
                init I1;            
                exit e1;
                end;
                
                I1  --> e1;
                end --> e1;
            }
            ";
{'fraction_non_alphanumeric': 0.08113556190156224, 'fraction_numerical': 0.02452544935326726, 'mean_word_length': 1.2158541123930033, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6098680', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1492, 'n_words': 301}