github.com/xyproto/orbiton/v2@v2.65.12-0.20240516144430-e10a419274ec/spellcheck_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestSearchForTypo(t *testing.T) {
     8  	e := NewSimpleEditor(80)
     9  
    10  	// Setup the Editor content with a typo
    11  	e.InsertStringAndMove(nil, "helllo world")
    12  	// Assuming "helllo" is a typo
    13  	typos, corrected, err := e.SearchForTypo()
    14  	if err != nil {
    15  		t.Fatalf("Error encountered when searching for typo: %s", err)
    16  	}
    17  	if typos != "helllo" {
    18  		t.Fatalf("Expected typo \"helllo\" but got \"%s\".", typos)
    19  	}
    20  	// Assuming the correction for "helllo" is "hello"
    21  	if corrected != "hello" {
    22  		t.Fatalf("Expected corrected word \"hello\" but got \"%s\".", corrected)
    23  	}
    24  }
    25  
    26  func TestSpellCheckerTraining(t *testing.T) {
    27  	sc, _ := NewSpellChecker()
    28  	initialModel := sc.fuzzyModel
    29  	sc.Train(true) // force re-train
    30  	if sc.fuzzyModel == initialModel {
    31  		t.Fatal("Fuzzy model did not retrain as expected.")
    32  	}
    33  }
    34  
    35  func TestDefaultSpellCheckerInitialization(t *testing.T) {
    36  	if spellChecker == nil {
    37  		t.Fatal("Default spell checker is not initialized.")
    38  	}
    39  	if len(spellChecker.correctWords) == 0 {
    40  		t.Fatal("Default spell checker has no correct words loaded.")
    41  	}
    42  }
    43  
    44  func TestNoTypo(t *testing.T) {
    45  	e := NewSimpleEditor(80)
    46  	e.InsertStringAndMove(nil, "This is a correct sentence.")
    47  
    48  	_, _, err := e.SearchForTypo()
    49  	if err != errFoundNoTypos {
    50  		t.Fatal("Expected 'errFoundNoTypos' when searching for typo in a correct sentence.")
    51  	}
    52  }