Skip to content

Commit

Permalink
feature: add Script Languages enum and coresponding unit tests 📝
Browse files Browse the repository at this point in the history
  • Loading branch information
GokselKUCUKSAHIN committed Feb 16, 2025
1 parent b2eb9d1 commit e2ce580
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
39 changes: 39 additions & 0 deletions es/enums/script-language/script_language.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package scriptlanguage

// ScriptLanguage represents the different scripting languages supported by Elasticsearch.
//
// ScriptLanguage is a string type used to specify the language of a script in Elasticsearch queries.
// It defines various options for scripting, allowing users to perform advanced calculations,
// filtering, and custom scoring within search queries.
//
// Example usage:
//
// var lang ScriptLanguage = Painless
//
// // Use lang in a script configuration
//
// Constants:
// - Painless: The default and most efficient scripting language in Elasticsearch.
// - Expression: A lightweight, fast scripting language for numeric calculations.
// - Mustache: A template-based scripting language used for rendering responses.
// - Java: A scripting option that allows Java code execution within queries.
type ScriptLanguage string

const (
// Painless is the default scripting language in Elasticsearch, optimized for performance and security.
Painless ScriptLanguage = "painless"

// Expression is a simple and fast scripting language for numeric computations.
Expression ScriptLanguage = "expression"

// Mustache is a templating language used for response rendering in Elasticsearch.
Mustache ScriptLanguage = "mustache"

// Java allows executing Java-based scripts in Elasticsearch.
Java ScriptLanguage = "java"
)

// String returns the string representation of the ScriptLanguage.
func (scriptLanguage ScriptLanguage) String() string {
return string(scriptLanguage)
}
27 changes: 27 additions & 0 deletions es/enums/script-language/script_language_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package scriptlanguage_test

import (
"testing"

ScriptLanguage "github.com/Trendyol/es-query-builder/es/enums/script-language"

"github.com/Trendyol/es-query-builder/test/assert"
)

func Test_ScriptLanguageString(t *testing.T) {
tests := []struct {
scriptLanguage ScriptLanguage.ScriptLanguage
result string
}{
{ScriptLanguage.Painless, "painless"},
{ScriptLanguage.Expression, "expression"},
{ScriptLanguage.Mustache, "mustache"},
{ScriptLanguage.Java, "java"},
}

for _, test := range tests {
t.Run(test.result, func(t *testing.T) {
assert.Equal(t, test.result, test.scriptLanguage.String())
})
}
}

0 comments on commit e2ce580

Please sign in to comment.