Following Changes have been made in addition to `https://github.com/aditya-K2/goMP/pull/5/commits/1572a460b042c25c93d4d5ed27b1a75432a53464` 1. config.go : ReadMappings Reads Array for each function Basically we are going to define mappings like this : ```yml Function : - first mapping - second mapping - third mapping ````` 2. kMap.go : GetAsciiValues will help us to get e.Rune() for the event for the handler function. So basically we will have a keymappings map generated which will help us to handle events. for e.g if an user has defined following mappings ````yml togglePlayBack : - P - p - B ```` then the keymappings map will look like this []keymappings = { GetAsciiValues("P") : togglePlayBack(), GetAsciiValues("p") : togglePlayBack(), GetAsciiValues("B") : togglePlayBack(), } so when the handler function will get an event e we will just pass it to this keymappings map i.e keymappings[e] which will return the function
33 lines
817 B
Go
33 lines
817 B
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestGetAsciiValue(t *testing.T) {
|
|
for k, v := range KMAP {
|
|
result, err := GetAsciiValue(k)
|
|
if result != v {
|
|
t.Errorf("Values From KMAP Failed")
|
|
} else if err != nil {
|
|
t.Errorf("Error Received: %v", err)
|
|
}
|
|
}
|
|
for i := 65; i < (65 + 26); i++ {
|
|
result, err := GetAsciiValue(string(rune(i)))
|
|
if err != nil {
|
|
t.Errorf("Error Received! %v", err)
|
|
} else if result != i {
|
|
t.Errorf("Invalid Value Received for small alphabets Result Received: %d expecting %d", result, i)
|
|
}
|
|
}
|
|
for i := 97; i < (97 + 26); i++ {
|
|
result, err := GetAsciiValue(string(rune(i)))
|
|
if err != nil {
|
|
t.Errorf("Error Received: %v", err)
|
|
} else if result != i {
|
|
t.Errorf("Invalid Value Received for Big alphabets Result Received: %d expecting %d", result, i)
|
|
}
|
|
}
|
|
}
|