package worldLanguages_test

import "testing"

import "seekia/internal/worldLanguages"

import "seekia/internal/helpers"

import "strings"

func TestWorldLanguages(t *testing.T){

	err := worldLanguages.InitializeWorldLanguageVariables()
	if (err != nil){
		t.Fatal("Failed to initialize worldLanguageVariables: " + err.Error())
	}

	// We must check to make sure no identifier or name collisions exist

	languageIdentifiersMap := make(map[int]struct{})

	languageNamesMap := make(map[string]struct{})

	worldLanguageObjectsList, err := worldLanguages.GetWorldLanguageObjectsList()
	if (err != nil){
		t.Fatal("Failed to get WorldLanguageObjectsList: " + err.Error())
	}

	for _, languageObject := range worldLanguageObjectsList{

		languageIdentifier := languageObject.Identifier
		languageNamesList := languageObject.NamesList

		_, exists := languageIdentifiersMap[languageIdentifier]
		if (exists == true){
			languageIdentifierString := helpers.ConvertIntToString(languageIdentifier)
			t.Fatal("Language identifier duplicate exists: " + languageIdentifierString)
		}
		
		languageIdentifiersMap[languageIdentifier] = struct{}{}

		if (len(languageNamesList) == 0){
			t.Fatal("Language contains empty names list.")
		}

		for _, languageName := range languageNamesList{

			// Each name cannot contain "+&" or ":"
			// Each name cannot be greater than 30 bytes

			if (len(languageName) > 30){
				t.Fatal("Language name is too long: " + languageName)
			}

			stringFound := strings.Contains(languageName, "+&")
			if (stringFound == true){
				t.Fatal("Invalid language name found: " + languageName)
			}

			stringFound = strings.Contains(languageName, "$")
			if (stringFound == true){
				t.Fatal("Invalid language name found: " + languageName)
			}

			_, exists := languageNamesMap[languageName]
			if (exists == true){
				t.Fatal("Language name duplicate exists: " + languageName)
			}
			languageNamesMap[languageName] = struct{}{}
		}
	}
}



