Skip to content
This repository
tree: f69cefdf9a
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 69 lines (61 sloc) 1.726 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
// Copyright 2011 The GoGL Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE.mkd file.

package main

import (
"strings"
"testing"
)

var testEnumsStr = "###########\n" +
"\n" +
"# comment 1\n" +
" ### comment 2\n" +
" #comment 3\n" +
"cat_1 enum:\n" +
"# comment\n" +
"enum1 = 0x00000100 \n" +
"enum2 = 0x00000200 # comment 2\n" +
"passthru: /* passthru comment */\n" +
"enum3 = 6 # comment 3\n" +
"cat_2 enum:\n" +
"# comment\n" +
"enum1 = 0x00000600 # comment 1\n" +
"enum2 = 0x00000800\n" +
"passthru: /* passthru comment */\n" +
"enum3 = 2 # comment 2\n" +
"cat_3 enum:\n" +
"# comment\n" +
"use cat_2 enum2 # comment 1\n"

func checkEnum(cat, en, value string, ecats EnumCategories, t *testing.T) {
if enums, ok := ecats[cat]; ok {
if e, ok := enums[en]; ok {
if e.Value == value {
t.Logf("Enum found: %v::%v = %v", cat, en, value)
return
}
t.Errorf("Enums not equal: %v: %v != %v", cat, value, e.Value)
return
}
t.Errorf("Enum not found: %v::%v", cat, en)
return
}
t.Errorf("Category not found: %v", cat)
}

func TestReadEnums(t *testing.T) {
r := strings.NewReader(testEnumsStr)
e, err := ReadEnums(r)
if err != nil {
t.Fatalf("Read enums failed: %v", err)
}
t.Logf("%v", e)

if len(e) != 3 {
t.Errorf("Wrong number of categories.")
}

checkEnum("cat_1", "enum1", "0x00000100", e, t)
checkEnum("cat_1", "enum2", "0x00000200", e, t)
checkEnum("cat_1", "enum3", "6", e, t)
checkEnum("cat_2", "enum1", "0x00000600", e, t)
checkEnum("cat_2", "enum2", "0x00000800", e, t)
checkEnum("cat_2", "enum3", "2", e, t)
checkEnum("cat_3", "enum2", "0x00000800", e, t)
}
Something went wrong with that request. Please try again.