<commit_before>﻿namespace MonoDevelopTests
open System
open NUnit.Framework
open MonoDevelop.FSharp
open MonoDevelop.Core
open MonoDevelop.Ide.Gui
open MonoDevelop.Ide.Gui.Content
open FSharp.CompilerBinding
open MonoDevelop.Projects
open MonoDevelop.Ide.TypeSystem
open FsUnit
open MonoDevelop.Debugger

[<TestFixture>]
type IndentationTrackerTests() =
    inherit TestBase()
    let content = """
let a = 

let b = (fun a ->

  let b = a
"""

    let docWithCaret (content:string) = 
        let d = fst(TestHelpers.createDoc(content.Replace("§", "")) [])
        do match content.IndexOf('§') with
           | -1 -> ()
           | x  -> let l = d.Editor.OffsetToLocation(x)
                   d.Editor.SetCaretLocation(l.Line, l.Column)
        d

    let getBasicOffset expr =
        let startOffset = content.IndexOf (expr, StringComparison.Ordinal)
        startOffset + (expr.Length / 2)

    let getIndent (doc:Document, content:string, line:int, col) =
        doc.Editor.SetCaretLocation (2, 2)
        let column = doc.Editor.GetVirtualIndentationColumn (line)
        column
           
    [<Test>]
    member x.BasicIndents() =
       // let basicOffset = getBasicOffset (localVariable)
        let doc = fst(TestHelpers.createDoc(content) [])
        getIndent (doc, content, 3, 1) |> should equal 5
        getIndent (doc, content, 5, 1) |> should equal 5
        getIndent (doc, content, 7, 1) |> should equal 3


    [<Test>]
    member x.MatchExpression() =
        let doc = docWithCaret("""let m = match 123 with§""")
        doc.Editor.GetVirtualIndentationColumn(9)

        |> should equal 9

    [<Test>]
    [<Ignore("InsertAtCaret doesn't simulate what happens when you press enter in MD, so this test currently fails")>]
    member x.EnterDoesntChangeIndentationAtIndentPosition() =
        let doc = docWithCaret("""  let a = 123
  §let b = 321""")
        doc.Editor.InsertAtCaret("\n")
        doc.Editor.Text 
        |> should equal @"  let a = 123

  let b = 321"
<commit_msg>Fixed indentation tracker tests, added match ident test<commit_after>﻿namespace MonoDevelopTests
open System
open NUnit.Framework
open MonoDevelop.FSharp
open MonoDevelop.Core
open MonoDevelop.Ide.Gui
open MonoDevelop.Ide.Gui.Content
open FSharp.CompilerBinding
open MonoDevelop.Projects
open MonoDevelop.Ide.TypeSystem
open FsUnit
open MonoDevelop.Debugger

[<TestFixture>]
type IndentationTrackerTests() =
    inherit TestBase()
    let content = """
let a = 

let b = (fun a ->

  let b = a
"""

    let docWithCaret (content:string) = 
        let d = fst(TestHelpers.createDoc(content.Replace("§", "")) [])
        d.Editor.SetIndentationTracker (FSharpIndentationTracker(d.Editor))
        do match content.IndexOf('§') with
           | -1 -> ()
           | x  -> let l = d.Editor.OffsetToLocation(x)
                   d.Editor.SetCaretLocation(l.Line, l.Column)
        d

    let getBasicOffset expr =
        let startOffset = content.IndexOf (expr, StringComparison.Ordinal)
        startOffset + (expr.Length / 2)

    let getIndent (doc:Document, content:string, line:int, col) =
        doc.Editor.SetCaretLocation (2, 2)
        let column = doc.Editor.GetVirtualIndentationColumn (line)
        column
           
    [<Test>]
    member x.BasicIndents() =
       // let basicOffset = getBasicOffset (localVariable)
        let doc = fst(TestHelpers.createDoc(content) [])
        doc.Editor.SetIndentationTracker (FSharpIndentationTracker(doc.Editor))
        getIndent (doc, content, 3, 1) |> should equal 5
        getIndent (doc, content, 5, 1) |> should equal 5
        getIndent (doc, content, 7, 1) |> should equal 3


    [<Test>]
    member x.MatchExpression() =
        let doc = docWithCaret("""let m = match 123 with§""")
        doc.Editor.InsertAtCaret("\n")
        doc.Editor.GetVirtualIndentationColumn(doc.Editor.CaretLine)
        |> should equal 9

    [<Test>]
    member x.IndentedMatchExpression() =
        let doc = docWithCaret("""let m =
   match 123 with§""")
        doc.Editor.InsertAtCaret("\n")
        doc.Editor.GetVirtualIndentationColumn(doc.Editor.CaretLine)
        |> should equal 4
  
    [<Test>]
    [<Ignore("InsertAtCaret doesn't simulate what happens when you press enter in MD, so this test currently fails")>]
    member x.EnterDoesntChangeIndentationAtIndentPosition() =
        let doc = docWithCaret("""  let a = 123
  §let b = 321""")
        doc.Editor.InsertAtCaret("\n")
        doc.Editor.Text 
        |> should equal @"  let a = 123

  let b = 321"

{'fraction_non_alphanumeric': 0.11461318051575932, 'fraction_numerical': 0.013885827639409301, 'mean_word_length': 2.7628524046434495, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3527879', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1383, 'n_words': 365}