You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2015/11/21 01:43:02 UTC
[37/42] incubator-mynewt-newt git commit: Move newt source into a
"newt" subdirectory.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/Godeps/_workspace/src/github.com/magiconair/properties/properties.go
----------------------------------------------------------------------
diff --git a/Godeps/_workspace/src/github.com/magiconair/properties/properties.go b/Godeps/_workspace/src/github.com/magiconair/properties/properties.go
deleted file mode 100644
index edcaccc..0000000
--- a/Godeps/_workspace/src/github.com/magiconair/properties/properties.go
+++ /dev/null
@@ -1,698 +0,0 @@
-// Copyright 2013-2014 Frank Schroeder. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package properties
-
-// BUG(frank): Set() does not check for invalid unicode literals since this is currently handled by the lexer.
-// BUG(frank): Write() does not allow to configure the newline character. Therefore, on Windows LF is used.
-
-import (
- "fmt"
- "io"
- "log"
- "os"
- "regexp"
- "strconv"
- "strings"
- "time"
- "unicode/utf8"
-)
-
-// ErrorHandlerFunc defines the type of function which handles failures
-// of the MustXXX() functions. An error handler function must exit
-// the application after handling the error.
-type ErrorHandlerFunc func(error)
-
-// ErrorHandler is the function which handles failures of the MustXXX()
-// functions. The default is LogFatalHandler.
-var ErrorHandler = LogFatalHandler
-
-// LogFatalHandler handles the error by logging a fatal error and exiting.
-func LogFatalHandler(err error) {
- log.Fatal(err)
-}
-
-// PanicHandler handles the error by panicking.
-func PanicHandler(err error) {
- panic(err)
-}
-
-// -----------------------------------------------------------------------------
-
-// A Properties contains the key/value pairs from the properties input.
-// All values are stored in unexpanded form and are expanded at runtime
-type Properties struct {
- // Pre-/Postfix for property expansion.
- Prefix string
- Postfix string
-
- // Stores the key/value pairs
- m map[string]string
-
- // Stores the comments per key.
- c map[string][]string
-
- // Stores the keys in order of appearance.
- k []string
-}
-
-// NewProperties creates a new Properties struct with the default
-// configuration for "${key}" expressions.
-func NewProperties() *Properties {
- return &Properties{
- Prefix: "${",
- Postfix: "}",
- m: map[string]string{},
- c: map[string][]string{},
- k: []string{},
- }
-}
-
-// Get returns the expanded value for the given key if exists.
-// Otherwise, ok is false.
-func (p *Properties) Get(key string) (value string, ok bool) {
- v, ok := p.m[key]
- if !ok {
- return "", false
- }
-
- expanded, err := p.expand(v)
-
- // we guarantee that the expanded value is free of
- // circular references and malformed expressions
- // so we panic if we still get an error here.
- if err != nil {
- ErrorHandler(fmt.Errorf("%s in %q", err, key+" = "+v))
- }
-
- return expanded, true
-}
-
-// MustGet returns the expanded value for the given key if exists.
-// Otherwise, it panics.
-func (p *Properties) MustGet(key string) string {
- if v, ok := p.Get(key); ok {
- return v
- }
- ErrorHandler(invalidKeyError(key))
- panic("ErrorHandler should exit")
-}
-
-// ----------------------------------------------------------------------------
-
-// ClearComments removes the comments for all keys.
-func (p *Properties) ClearComments() {
- p.c = map[string][]string{}
-}
-
-// ----------------------------------------------------------------------------
-
-// GetComment returns the last comment before the given key or an empty string.
-func (p *Properties) GetComment(key string) string {
- comments, ok := p.c[key]
- if !ok || len(comments) == 0 {
- return ""
- }
- return comments[len(comments)-1]
-}
-
-// ----------------------------------------------------------------------------
-
-// GetComments returns all comments that appeared before the given key or nil.
-func (p *Properties) GetComments(key string) []string {
- if comments, ok := p.c[key]; ok {
- return comments
- }
- return nil
-}
-
-// ----------------------------------------------------------------------------
-
-// SetComment sets the comment for the key.
-func (p *Properties) SetComment(key, comment string) {
- p.c[key] = []string{comment}
-}
-
-// ----------------------------------------------------------------------------
-
-// SetComments sets the comments for the key. If the comments are nil then
-// all comments for this key are deleted.
-func (p *Properties) SetComments(key string, comments []string) {
- if comments == nil {
- delete(p.c, key)
- return
- }
- p.c[key] = comments
-}
-
-// ----------------------------------------------------------------------------
-
-// GetBool checks if the expanded value is one of '1', 'yes',
-// 'true' or 'on' if the key exists. The comparison is case-insensitive.
-// If the key does not exist the default value is returned.
-func (p *Properties) GetBool(key string, def bool) bool {
- v, err := p.getBool(key)
- if err != nil {
- return def
- }
- return v
-}
-
-// MustGetBool checks if the expanded value is one of '1', 'yes',
-// 'true' or 'on' if the key exists. The comparison is case-insensitive.
-// If the key does not exist the function panics.
-func (p *Properties) MustGetBool(key string) bool {
- v, err := p.getBool(key)
- if err != nil {
- ErrorHandler(err)
- }
- return v
-}
-
-func (p *Properties) getBool(key string) (value bool, err error) {
- if v, ok := p.Get(key); ok {
- v = strings.ToLower(v)
- return v == "1" || v == "true" || v == "yes" || v == "on", nil
- }
- return false, invalidKeyError(key)
-}
-
-// ----------------------------------------------------------------------------
-
-// GetDuration parses the expanded value as an time.Duration (in ns) if the
-// key exists. If key does not exist or the value cannot be parsed the default
-// value is returned. In almost all cases you want to use GetParsedDuration().
-func (p *Properties) GetDuration(key string, def time.Duration) time.Duration {
- v, err := p.getInt64(key)
- if err != nil {
- return def
- }
- return time.Duration(v)
-}
-
-// MustGetDuration parses the expanded value as an time.Duration (in ns) if
-// the key exists. If key does not exist or the value cannot be parsed the
-// function panics. In almost all cases you want to use MustGetParsedDuration().
-func (p *Properties) MustGetDuration(key string) time.Duration {
- v, err := p.getInt64(key)
- if err != nil {
- ErrorHandler(err)
- }
- return time.Duration(v)
-}
-
-// ----------------------------------------------------------------------------
-
-// GetParsedDuration parses the expanded value with time.ParseDuration() if the key exists.
-// If key does not exist or the value cannot be parsed the default
-// value is returned.
-func (p *Properties) GetParsedDuration(key string, def time.Duration) time.Duration {
- s, ok := p.Get(key)
- if !ok {
- return def
- }
- v, err := time.ParseDuration(s)
- if err != nil {
- return def
- }
- return v
-}
-
-// MustGetParsedDuration parses the expanded value with time.ParseDuration() if the key exists.
-// If key does not exist or the value cannot be parsed the function panics.
-func (p *Properties) MustGetParsedDuration(key string) time.Duration {
- s, ok := p.Get(key)
- if !ok {
- ErrorHandler(invalidKeyError(key))
- }
- v, err := time.ParseDuration(s)
- if err != nil {
- ErrorHandler(err)
- }
- return v
-}
-
-// ----------------------------------------------------------------------------
-
-// GetFloat64 parses the expanded value as a float64 if the key exists.
-// If key does not exist or the value cannot be parsed the default
-// value is returned.
-func (p *Properties) GetFloat64(key string, def float64) float64 {
- v, err := p.getFloat64(key)
- if err != nil {
- return def
- }
- return v
-}
-
-// MustGetFloat64 parses the expanded value as a float64 if the key exists.
-// If key does not exist or the value cannot be parsed the function panics.
-func (p *Properties) MustGetFloat64(key string) float64 {
- v, err := p.getFloat64(key)
- if err != nil {
- ErrorHandler(err)
- }
- return v
-}
-
-func (p *Properties) getFloat64(key string) (value float64, err error) {
- if v, ok := p.Get(key); ok {
- value, err = strconv.ParseFloat(v, 64)
- if err != nil {
- return 0, err
- }
- return value, nil
- }
- return 0, invalidKeyError(key)
-}
-
-// ----------------------------------------------------------------------------
-
-// GetInt parses the expanded value as an int if the key exists.
-// If key does not exist or the value cannot be parsed the default
-// value is returned. If the value does not fit into an int the
-// function panics with an out of range error.
-func (p *Properties) GetInt(key string, def int) int {
- v, err := p.getInt64(key)
- if err != nil {
- return def
- }
- return intRangeCheck(key, v)
-}
-
-// MustGetInt parses the expanded value as an int if the key exists.
-// If key does not exist or the value cannot be parsed the function panics.
-// If the value does not fit into an int the function panics with
-// an out of range error.
-func (p *Properties) MustGetInt(key string) int {
- v, err := p.getInt64(key)
- if err != nil {
- ErrorHandler(err)
- }
- return intRangeCheck(key, v)
-}
-
-// ----------------------------------------------------------------------------
-
-// GetInt64 parses the expanded value as an int64 if the key exists.
-// If key does not exist or the value cannot be parsed the default
-// value is returned.
-func (p *Properties) GetInt64(key string, def int64) int64 {
- v, err := p.getInt64(key)
- if err != nil {
- return def
- }
- return v
-}
-
-// MustGetInt64 parses the expanded value as an int if the key exists.
-// If key does not exist or the value cannot be parsed the function panics.
-func (p *Properties) MustGetInt64(key string) int64 {
- v, err := p.getInt64(key)
- if err != nil {
- ErrorHandler(err)
- }
- return v
-}
-
-func (p *Properties) getInt64(key string) (value int64, err error) {
- if v, ok := p.Get(key); ok {
- value, err = strconv.ParseInt(v, 10, 64)
- if err != nil {
- return 0, err
- }
- return value, nil
- }
- return 0, invalidKeyError(key)
-}
-
-// ----------------------------------------------------------------------------
-
-// GetUint parses the expanded value as an uint if the key exists.
-// If key does not exist or the value cannot be parsed the default
-// value is returned. If the value does not fit into an int the
-// function panics with an out of range error.
-func (p *Properties) GetUint(key string, def uint) uint {
- v, err := p.getUint64(key)
- if err != nil {
- return def
- }
- return uintRangeCheck(key, v)
-}
-
-// MustGetUint parses the expanded value as an int if the key exists.
-// If key does not exist or the value cannot be parsed the function panics.
-// If the value does not fit into an int the function panics with
-// an out of range error.
-func (p *Properties) MustGetUint(key string) uint {
- v, err := p.getUint64(key)
- if err != nil {
- ErrorHandler(err)
- }
- return uintRangeCheck(key, v)
-}
-
-// ----------------------------------------------------------------------------
-
-// GetUint64 parses the expanded value as an uint64 if the key exists.
-// If key does not exist or the value cannot be parsed the default
-// value is returned.
-func (p *Properties) GetUint64(key string, def uint64) uint64 {
- v, err := p.getUint64(key)
- if err != nil {
- return def
- }
- return v
-}
-
-// MustGetUint64 parses the expanded value as an int if the key exists.
-// If key does not exist or the value cannot be parsed the function panics.
-func (p *Properties) MustGetUint64(key string) uint64 {
- v, err := p.getUint64(key)
- if err != nil {
- ErrorHandler(err)
- }
- return v
-}
-
-func (p *Properties) getUint64(key string) (value uint64, err error) {
- if v, ok := p.Get(key); ok {
- value, err = strconv.ParseUint(v, 10, 64)
- if err != nil {
- return 0, err
- }
- return value, nil
- }
- return 0, invalidKeyError(key)
-}
-
-// ----------------------------------------------------------------------------
-
-// GetString returns the expanded value for the given key if exists or
-// the default value otherwise.
-func (p *Properties) GetString(key, def string) string {
- if v, ok := p.Get(key); ok {
- return v
- }
- return def
-}
-
-// MustGetString returns the expanded value for the given key if exists or
-// panics otherwise.
-func (p *Properties) MustGetString(key string) string {
- if v, ok := p.Get(key); ok {
- return v
- }
- ErrorHandler(invalidKeyError(key))
- panic("ErrorHandler should exit")
-}
-
-// ----------------------------------------------------------------------------
-
-// Filter returns a new properties object which contains all properties
-// for which the key matches the pattern.
-func (p *Properties) Filter(pattern string) (*Properties, error) {
- re, err := regexp.Compile(pattern)
- if err != nil {
- return nil, err
- }
-
- return p.FilterRegexp(re), nil
-}
-
-// FilterRegexp returns a new properties object which contains all properties
-// for which the key matches the regular expression.
-func (p *Properties) FilterRegexp(re *regexp.Regexp) *Properties {
- pp := NewProperties()
- for _, k := range p.k {
- if re.MatchString(k) {
- pp.Set(k, p.m[k])
- }
- }
- return pp
-}
-
-// FilterPrefix returns a new properties object which contains all properties
-// for which the key starts with the prefix.
-func (p *Properties) FilterPrefix(prefix string) *Properties {
- pp := NewProperties()
- for _, k := range p.k {
- if strings.HasPrefix(k, prefix) {
- pp.Set(k, p.m[k])
- }
- }
- return pp
-}
-
-// Len returns the number of keys.
-func (p *Properties) Len() int {
- return len(p.m)
-}
-
-// Keys returns all keys in the same order as in the input.
-func (p *Properties) Keys() []string {
- keys := make([]string, len(p.k))
- for i, k := range p.k {
- keys[i] = k
- }
- return keys
-}
-
-// Set sets the property key to the corresponding value.
-// If a value for key existed before then ok is true and prev
-// contains the previous value. If the value contains a
-// circular reference or a malformed expression then
-// an error is returned.
-// An empty key is silently ignored.
-func (p *Properties) Set(key, value string) (prev string, ok bool, err error) {
- if key == "" {
- return "", false, nil
- }
-
- // to check for a circular reference we temporarily need
- // to set the new value. If there is an error then revert
- // to the previous state. Only if all tests are successful
- // then we add the key to the p.k list.
- prev, ok = p.Get(key)
- p.m[key] = value
-
- // now check for a circular reference
- _, err = p.expand(value)
- if err != nil {
-
- // revert to the previous state
- if ok {
- p.m[key] = prev
- } else {
- delete(p.m, key)
- }
-
- return "", false, err
- }
-
- if !ok {
- p.k = append(p.k, key)
- }
-
- return prev, ok, nil
-}
-
-// MustSet sets the property key to the corresponding value.
-// If a value for key existed before then ok is true and prev
-// contains the previous value. An empty key is silently ignored.
-func (p *Properties) MustSet(key, value string) (prev string, ok bool) {
- prev, ok, err := p.Set(key, value)
- if err != nil {
- ErrorHandler(err)
- }
- return prev, ok
-}
-
-// String returns a string of all expanded 'key = value' pairs.
-func (p *Properties) String() string {
- var s string
- for _, key := range p.k {
- value, _ := p.Get(key)
- s = fmt.Sprintf("%s%s = %s\n", s, key, value)
- }
- return s
-}
-
-// Write writes all unexpanded 'key = value' pairs to the given writer.
-// Write returns the number of bytes written and any write error encountered.
-func (p *Properties) Write(w io.Writer, enc Encoding) (n int, err error) {
- return p.WriteComment(w, "", enc)
-}
-
-// WriteComment writes all unexpanced 'key = value' pairs to the given writer.
-// If prefix is not empty then comments are written with a blank line and the
-// given prefix. The prefix should be either "# " or "! " to be compatible with
-// the properties file format. Otherwise, the properties parser will not be
-// able to read the file back in. It returns the number of bytes written and
-// any write error encountered.
-func (p *Properties) WriteComment(w io.Writer, prefix string, enc Encoding) (n int, err error) {
- var x int
-
- for _, key := range p.k {
- value := p.m[key]
-
- if prefix != "" {
- if comments, ok := p.c[key]; ok {
- // don't print comments if they are all empty
- allEmpty := true
- for _, c := range comments {
- if c != "" {
- allEmpty = false
- break
- }
- }
-
- if !allEmpty {
- // add a blank line between entries but not at the top
- if len(comments) > 0 && n > 0 {
- x, err = fmt.Fprintln(w)
- if err != nil {
- return
- }
- n += x
- }
-
- for _, c := range comments {
- x, err = fmt.Fprintf(w, "%s%s\n", prefix, encode(c, "", enc))
- if err != nil {
- return
- }
- n += x
- }
- }
- }
- }
-
- x, err = fmt.Fprintf(w, "%s = %s\n", encode(key, " :", enc), encode(value, "", enc))
- if err != nil {
- return
- }
- n += x
- }
- return
-}
-
-// ----------------------------------------------------------------------------
-
-// check expands all values and returns an error if a circular reference or
-// a malformed expression was found.
-func (p *Properties) check() error {
- for _, value := range p.m {
- if _, err := p.expand(value); err != nil {
- return err
- }
- }
- return nil
-}
-
-func (p *Properties) expand(input string) (string, error) {
- // no pre/postfix -> nothing to expand
- if p.Prefix == "" && p.Postfix == "" {
- return input, nil
- }
-
- return expand(input, make(map[string]bool), p.Prefix, p.Postfix, p.m)
-}
-
-// expand recursively expands expressions of '(prefix)key(postfix)' to their corresponding values.
-// The function keeps track of the keys that were already expanded and stops if it
-// detects a circular reference or a malformed expression of the form '(prefix)key'.
-func expand(s string, keys map[string]bool, prefix, postfix string, values map[string]string) (string, error) {
- start := strings.Index(s, prefix)
- if start == -1 {
- return s, nil
- }
-
- keyStart := start + len(prefix)
- keyLen := strings.Index(s[keyStart:], postfix)
- if keyLen == -1 {
- return "", fmt.Errorf("malformed expression")
- }
-
- end := keyStart + keyLen + len(postfix) - 1
- key := s[keyStart : keyStart+keyLen]
-
- // fmt.Printf("s:%q pp:%q start:%d end:%d keyStart:%d keyLen:%d key:%q\n", s, prefix + "..." + postfix, start, end, keyStart, keyLen, key)
-
- if _, ok := keys[key]; ok {
- return "", fmt.Errorf("circular reference")
- }
-
- val, ok := values[key]
- if !ok {
- val = os.Getenv(key)
- }
-
- // remember that we've seen the key
- keys[key] = true
-
- return expand(s[:start]+val+s[end+1:], keys, prefix, postfix, values)
-}
-
-// encode encodes a UTF-8 string to ISO-8859-1 and escapes some characters.
-func encode(s string, special string, enc Encoding) string {
- switch enc {
- case UTF8:
- return encodeUtf8(s, special)
- case ISO_8859_1:
- return encodeIso(s, special)
- default:
- panic(fmt.Sprintf("unsupported encoding %v", enc))
- }
-}
-
-func encodeUtf8(s string, special string) string {
- v := ""
- for pos := 0; pos < len(s); {
- r, w := utf8.DecodeRuneInString(s[pos:])
- pos += w
- v += escape(r, special)
- }
- return v
-}
-
-func encodeIso(s string, special string) string {
- var r rune
- var w int
- var v string
- for pos := 0; pos < len(s); {
- switch r, w = utf8.DecodeRuneInString(s[pos:]); {
- case r < 1<<8: // single byte rune -> escape special chars only
- v += escape(r, special)
- case r < 1<<16: // two byte rune -> unicode literal
- v += fmt.Sprintf("\\u%04x", r)
- default: // more than two bytes per rune -> can't encode
- v += "?"
- }
- pos += w
- }
- return v
-}
-
-func escape(r rune, special string) string {
- switch r {
- case '\f':
- return "\\f"
- case '\n':
- return "\\n"
- case '\r':
- return "\\r"
- case '\t':
- return "\\t"
- default:
- if strings.ContainsRune(special, r) {
- return "\\" + string(r)
- }
- return string(r)
- }
-}
-
-func invalidKeyError(key string) error {
- return fmt.Errorf("unknown property: %s", key)
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/Godeps/_workspace/src/github.com/magiconair/properties/properties_test.go
----------------------------------------------------------------------
diff --git a/Godeps/_workspace/src/github.com/magiconair/properties/properties_test.go b/Godeps/_workspace/src/github.com/magiconair/properties/properties_test.go
deleted file mode 100644
index 36ff293..0000000
--- a/Godeps/_workspace/src/github.com/magiconair/properties/properties_test.go
+++ /dev/null
@@ -1,846 +0,0 @@
-// Copyright 2013-2014 Frank Schroeder. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package properties
-
-import (
- "bytes"
- "flag"
- "fmt"
- "math"
- "os"
- "strings"
- "testing"
- "time"
-
- . "gopkg.in/check.v1"
-)
-
-func Test(t *testing.T) { TestingT(t) }
-
-type TestSuite struct {
- prevHandler ErrorHandlerFunc
-}
-
-var (
- _ = Suite(&TestSuite{})
- verbose = flag.Bool("verbose", false, "Verbose output")
-)
-
-// --------------------------------------------------------------------
-
-func (s *TestSuite) SetUpSuite(c *C) {
- s.prevHandler = ErrorHandler
- ErrorHandler = PanicHandler
-}
-
-// --------------------------------------------------------------------
-
-func (s *TestSuite) TearDownSuite(c *C) {
- ErrorHandler = s.prevHandler
-}
-
-// ----------------------------------------------------------------------------
-
-// define test cases in the form of
-// {"input", "key1", "value1", "key2", "value2", ...}
-var complexTests = [][]string{
- // whitespace prefix
- {" key=value", "key", "value"}, // SPACE prefix
- {"\fkey=value", "key", "value"}, // FF prefix
- {"\tkey=value", "key", "value"}, // TAB prefix
- {" \f\tkey=value", "key", "value"}, // mix prefix
-
- // multiple keys
- {"key1=value1\nkey2=value2\n", "key1", "value1", "key2", "value2"},
- {"key1=value1\rkey2=value2\r", "key1", "value1", "key2", "value2"},
- {"key1=value1\r\nkey2=value2\r\n", "key1", "value1", "key2", "value2"},
-
- // blank lines
- {"\nkey=value\n", "key", "value"},
- {"\rkey=value\r", "key", "value"},
- {"\r\nkey=value\r\n", "key", "value"},
-
- // escaped chars in key
- {"k\\ ey = value", "k ey", "value"},
- {"k\\:ey = value", "k:ey", "value"},
- {"k\\=ey = value", "k=ey", "value"},
- {"k\\fey = value", "k\fey", "value"},
- {"k\\ney = value", "k\ney", "value"},
- {"k\\rey = value", "k\rey", "value"},
- {"k\\tey = value", "k\tey", "value"},
-
- // escaped chars in value
- {"key = v\\ alue", "key", "v alue"},
- {"key = v\\:alue", "key", "v:alue"},
- {"key = v\\=alue", "key", "v=alue"},
- {"key = v\\falue", "key", "v\falue"},
- {"key = v\\nalue", "key", "v\nalue"},
- {"key = v\\ralue", "key", "v\ralue"},
- {"key = v\\talue", "key", "v\talue"},
-
- // silently dropped escape character
- {"k\\zey = value", "kzey", "value"},
- {"key = v\\zalue", "key", "vzalue"},
-
- // unicode literals
- {"key\\u2318 = value", "key⌘", "value"},
- {"k\\u2318ey = value", "k⌘ey", "value"},
- {"key = value\\u2318", "key", "value⌘"},
- {"key = valu\\u2318e", "key", "valu⌘e"},
-
- // multiline values
- {"key = valueA,\\\n valueB", "key", "valueA,valueB"}, // SPACE indent
- {"key = valueA,\\\n\f\f\fvalueB", "key", "valueA,valueB"}, // FF indent
- {"key = valueA,\\\n\t\t\tvalueB", "key", "valueA,valueB"}, // TAB indent
- {"key = valueA,\\\n \f\tvalueB", "key", "valueA,valueB"}, // mix indent
-
- // comments
- {"# this is a comment\n! and so is this\nkey1=value1\nkey#2=value#2\n\nkey!3=value!3\n# and another one\n! and the final one", "key1", "value1", "key#2", "value#2", "key!3", "value!3"},
-
- // expansion tests
- {"key=value\nkey2=${key}", "key", "value", "key2", "value"},
- {"key=value\nkey2=aa${key}", "key", "value", "key2", "aavalue"},
- {"key=value\nkey2=${key}bb", "key", "value", "key2", "valuebb"},
- {"key=value\nkey2=aa${key}bb", "key", "value", "key2", "aavaluebb"},
- {"key=value\nkey2=${key}\nkey3=${key2}", "key", "value", "key2", "value", "key3", "value"},
- {"key=${USER}", "key", os.Getenv("USER")},
- {"key=${USER}\nUSER=value", "key", "value", "USER", "value"},
-}
-
-// ----------------------------------------------------------------------------
-
-var commentTests = []struct {
- input, key, value string
- comments []string
-}{
- {"key=value", "key", "value", nil},
- {"#\nkey=value", "key", "value", []string{""}},
- {"#comment\nkey=value", "key", "value", []string{"comment"}},
- {"# comment\nkey=value", "key", "value", []string{"comment"}},
- {"# comment\nkey=value", "key", "value", []string{"comment"}},
- {"# comment\n\nkey=value", "key", "value", []string{"comment"}},
- {"# comment1\n# comment2\nkey=value", "key", "value", []string{"comment1", "comment2"}},
- {"# comment1\n\n# comment2\n\nkey=value", "key", "value", []string{"comment1", "comment2"}},
- {"!comment\nkey=value", "key", "value", []string{"comment"}},
- {"! comment\nkey=value", "key", "value", []string{"comment"}},
- {"! comment\nkey=value", "key", "value", []string{"comment"}},
- {"! comment\n\nkey=value", "key", "value", []string{"comment"}},
- {"! comment1\n! comment2\nkey=value", "key", "value", []string{"comment1", "comment2"}},
- {"! comment1\n\n! comment2\n\nkey=value", "key", "value", []string{"comment1", "comment2"}},
-}
-
-// ----------------------------------------------------------------------------
-
-var errorTests = []struct {
- input, msg string
-}{
- // unicode literals
- {"key\\u1 = value", "invalid unicode literal"},
- {"key\\u12 = value", "invalid unicode literal"},
- {"key\\u123 = value", "invalid unicode literal"},
- {"key\\u123g = value", "invalid unicode literal"},
- {"key\\u123", "invalid unicode literal"},
-
- // circular references
- {"key=${key}", "circular reference"},
- {"key1=${key2}\nkey2=${key1}", "circular reference"},
-
- // malformed expressions
- {"key=${ke", "malformed expression"},
- {"key=valu${ke", "malformed expression"},
-}
-
-// ----------------------------------------------------------------------------
-
-var writeTests = []struct {
- input, output, encoding string
-}{
- // ISO-8859-1 tests
- {"key = value", "key = value\n", "ISO-8859-1"},
- {"key = value \\\n continued", "key = value continued\n", "ISO-8859-1"},
- {"key⌘ = value", "key\\u2318 = value\n", "ISO-8859-1"},
- {"ke\\ \\:y = value", "ke\\ \\:y = value\n", "ISO-8859-1"},
-
- // UTF-8 tests
- {"key = value", "key = value\n", "UTF-8"},
- {"key = value \\\n continued", "key = value continued\n", "UTF-8"},
- {"key⌘ = value⌘", "key⌘ = value⌘\n", "UTF-8"},
- {"ke\\ \\:y = value", "ke\\ \\:y = value\n", "UTF-8"},
-}
-
-// ----------------------------------------------------------------------------
-
-var writeCommentTests = []struct {
- input, output, encoding string
-}{
- // ISO-8859-1 tests
- {"key = value", "key = value\n", "ISO-8859-1"},
- {"#\nkey = value", "key = value\n", "ISO-8859-1"},
- {"#\n#\n#\nkey = value", "key = value\n", "ISO-8859-1"},
- {"# comment\nkey = value", "# comment\nkey = value\n", "ISO-8859-1"},
- {"\n# comment\nkey = value", "# comment\nkey = value\n", "ISO-8859-1"},
- {"# comment\n\nkey = value", "# comment\nkey = value\n", "ISO-8859-1"},
- {"# comment1\n# comment2\nkey = value", "# comment1\n# comment2\nkey = value\n", "ISO-8859-1"},
- {"#comment1\nkey1 = value1\n#comment2\nkey2 = value2", "# comment1\nkey1 = value1\n\n# comment2\nkey2 = value2\n", "ISO-8859-1"},
-
- // UTF-8 tests
- {"key = value", "key = value\n", "UTF-8"},
- {"# comment⌘\nkey = value⌘", "# comment⌘\nkey = value⌘\n", "UTF-8"},
- {"\n# comment⌘\nkey = value⌘", "# comment⌘\nkey = value⌘\n", "UTF-8"},
- {"# comment⌘\n\nkey = value⌘", "# comment⌘\nkey = value⌘\n", "UTF-8"},
- {"# comment1⌘\n# comment2⌘\nkey = value⌘", "# comment1⌘\n# comment2⌘\nkey = value⌘\n", "UTF-8"},
- {"#comment1⌘\nkey1 = value1⌘\n#comment2⌘\nkey2 = value2⌘", "# comment1⌘\nkey1 = value1⌘\n\n# comment2⌘\nkey2 = value2⌘\n", "UTF-8"},
-}
-
-// ----------------------------------------------------------------------------
-
-var boolTests = []struct {
- input, key string
- def, value bool
-}{
- // valid values for TRUE
- {"key = 1", "key", false, true},
- {"key = on", "key", false, true},
- {"key = On", "key", false, true},
- {"key = ON", "key", false, true},
- {"key = true", "key", false, true},
- {"key = True", "key", false, true},
- {"key = TRUE", "key", false, true},
- {"key = yes", "key", false, true},
- {"key = Yes", "key", false, true},
- {"key = YES", "key", false, true},
-
- // valid values for FALSE (all other)
- {"key = 0", "key", true, false},
- {"key = off", "key", true, false},
- {"key = false", "key", true, false},
- {"key = no", "key", true, false},
-
- // non existent key
- {"key = true", "key2", false, false},
-}
-
-// ----------------------------------------------------------------------------
-
-var durationTests = []struct {
- input, key string
- def, value time.Duration
-}{
- // valid values
- {"key = 1", "key", 999, 1},
- {"key = 0", "key", 999, 0},
- {"key = -1", "key", 999, -1},
- {"key = 0123", "key", 999, 123},
-
- // invalid values
- {"key = 0xff", "key", 999, 999},
- {"key = 1.0", "key", 999, 999},
- {"key = a", "key", 999, 999},
-
- // non existent key
- {"key = 1", "key2", 999, 999},
-}
-
-// ----------------------------------------------------------------------------
-
-var parsedDurationTests = []struct {
- input, key string
- def, value time.Duration
-}{
- // valid values
- {"key = -1ns", "key", 999, -1 * time.Nanosecond},
- {"key = 300ms", "key", 999, 300 * time.Millisecond},
- {"key = 5s", "key", 999, 5 * time.Second},
- {"key = 3h", "key", 999, 3 * time.Hour},
- {"key = 2h45m", "key", 999, 2*time.Hour + 45*time.Minute},
-
- // invalid values
- {"key = 0xff", "key", 999, 999},
- {"key = 1.0", "key", 999, 999},
- {"key = a", "key", 999, 999},
- {"key = 1", "key", 999, 999},
- {"key = 0", "key", 999, 0},
-
- // non existent key
- {"key = 1", "key2", 999, 999},
-}
-
-// ----------------------------------------------------------------------------
-
-var floatTests = []struct {
- input, key string
- def, value float64
-}{
- // valid values
- {"key = 1.0", "key", 999, 1.0},
- {"key = 0.0", "key", 999, 0.0},
- {"key = -1.0", "key", 999, -1.0},
- {"key = 1", "key", 999, 1},
- {"key = 0", "key", 999, 0},
- {"key = -1", "key", 999, -1},
- {"key = 0123", "key", 999, 123},
-
- // invalid values
- {"key = 0xff", "key", 999, 999},
- {"key = a", "key", 999, 999},
-
- // non existent key
- {"key = 1", "key2", 999, 999},
-}
-
-// ----------------------------------------------------------------------------
-
-var int64Tests = []struct {
- input, key string
- def, value int64
-}{
- // valid values
- {"key = 1", "key", 999, 1},
- {"key = 0", "key", 999, 0},
- {"key = -1", "key", 999, -1},
- {"key = 0123", "key", 999, 123},
-
- // invalid values
- {"key = 0xff", "key", 999, 999},
- {"key = 1.0", "key", 999, 999},
- {"key = a", "key", 999, 999},
-
- // non existent key
- {"key = 1", "key2", 999, 999},
-}
-
-// ----------------------------------------------------------------------------
-
-var uint64Tests = []struct {
- input, key string
- def, value uint64
-}{
- // valid values
- {"key = 1", "key", 999, 1},
- {"key = 0", "key", 999, 0},
- {"key = 0123", "key", 999, 123},
-
- // invalid values
- {"key = -1", "key", 999, 999},
- {"key = 0xff", "key", 999, 999},
- {"key = 1.0", "key", 999, 999},
- {"key = a", "key", 999, 999},
-
- // non existent key
- {"key = 1", "key2", 999, 999},
-}
-
-// ----------------------------------------------------------------------------
-
-var stringTests = []struct {
- input, key string
- def, value string
-}{
- // valid values
- {"key = abc", "key", "def", "abc"},
-
- // non existent key
- {"key = abc", "key2", "def", "def"},
-}
-
-// ----------------------------------------------------------------------------
-
-var keysTests = []struct {
- input string
- keys []string
-}{
- {"", []string{}},
- {"key = abc", []string{"key"}},
- {"key = abc\nkey2=def", []string{"key", "key2"}},
- {"key2 = abc\nkey=def", []string{"key2", "key"}},
- {"key = abc\nkey=def", []string{"key"}},
-}
-
-// ----------------------------------------------------------------------------
-
-var filterTests = []struct {
- input string
- pattern string
- keys []string
- err string
-}{
- {"", "", []string{}, ""},
- {"", "abc", []string{}, ""},
- {"key=value", "", []string{"key"}, ""},
- {"key=value", "key=", []string{}, ""},
- {"key=value\nfoo=bar", "", []string{"foo", "key"}, ""},
- {"key=value\nfoo=bar", "f", []string{"foo"}, ""},
- {"key=value\nfoo=bar", "fo", []string{"foo"}, ""},
- {"key=value\nfoo=bar", "foo", []string{"foo"}, ""},
- {"key=value\nfoo=bar", "fooo", []string{}, ""},
- {"key=value\nkey2=value2\nfoo=bar", "ey", []string{"key", "key2"}, ""},
- {"key=value\nkey2=value2\nfoo=bar", "key", []string{"key", "key2"}, ""},
- {"key=value\nkey2=value2\nfoo=bar", "^key", []string{"key", "key2"}, ""},
- {"key=value\nkey2=value2\nfoo=bar", "^(key|foo)", []string{"foo", "key", "key2"}, ""},
- {"key=value\nkey2=value2\nfoo=bar", "[ abc", nil, "error parsing regexp.*"},
-}
-
-// ----------------------------------------------------------------------------
-
-var filterPrefixTests = []struct {
- input string
- prefix string
- keys []string
-}{
- {"", "", []string{}},
- {"", "abc", []string{}},
- {"key=value", "", []string{"key"}},
- {"key=value", "key=", []string{}},
- {"key=value\nfoo=bar", "", []string{"foo", "key"}},
- {"key=value\nfoo=bar", "f", []string{"foo"}},
- {"key=value\nfoo=bar", "fo", []string{"foo"}},
- {"key=value\nfoo=bar", "foo", []string{"foo"}},
- {"key=value\nfoo=bar", "fooo", []string{}},
- {"key=value\nkey2=value2\nfoo=bar", "key", []string{"key", "key2"}},
-}
-
-// ----------------------------------------------------------------------------
-
-var setTests = []struct {
- input string
- key, value string
- prev string
- ok bool
- err string
- keys []string
-}{
- {"", "", "", "", false, "", []string{}},
- {"", "key", "value", "", false, "", []string{"key"}},
- {"key=value", "key2", "value2", "", false, "", []string{"key", "key2"}},
- {"key=value", "abc", "value3", "", false, "", []string{"key", "abc"}},
- {"key=value", "key", "value3", "value", true, "", []string{"key"}},
-}
-
-// ----------------------------------------------------------------------------
-
-// TestBasic tests basic single key/value combinations with all possible
-// whitespace, delimiter and newline permutations.
-func (s *TestSuite) TestBasic(c *C) {
- testWhitespaceAndDelimiterCombinations(c, "key", "")
- testWhitespaceAndDelimiterCombinations(c, "key", "value")
- testWhitespaceAndDelimiterCombinations(c, "key", "value ")
-}
-
-func (s *TestSuite) TestComplex(c *C) {
- for _, test := range complexTests {
- testKeyValue(c, test[0], test[1:]...)
- }
-}
-
-func (s *TestSuite) TestErrors(c *C) {
- for _, test := range errorTests {
- _, err := Load([]byte(test.input), ISO_8859_1)
- c.Assert(err, NotNil)
- c.Assert(strings.Contains(err.Error(), test.msg), Equals, true, Commentf("Expected %q got %q", test.msg, err.Error()))
- }
-}
-
-func (s *TestSuite) TestMustGet(c *C) {
- input := "key = value\nkey2 = ghi"
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGet("key"), Equals, "value")
- c.Assert(func() { p.MustGet("invalid") }, PanicMatches, "unknown property: invalid")
-}
-
-func (s *TestSuite) TestGetBool(c *C) {
- for _, test := range boolTests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- c.Assert(p.Len(), Equals, 1)
- c.Assert(p.GetBool(test.key, test.def), Equals, test.value)
- }
-}
-
-func (s *TestSuite) TestMustGetBool(c *C) {
- input := "key = true\nkey2 = ghi"
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGetBool("key"), Equals, true)
- c.Assert(func() { p.MustGetBool("invalid") }, PanicMatches, "unknown property: invalid")
-}
-
-func (s *TestSuite) TestGetDuration(c *C) {
- for _, test := range durationTests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- c.Assert(p.Len(), Equals, 1)
- c.Assert(p.GetDuration(test.key, test.def), Equals, test.value)
- }
-}
-
-func (s *TestSuite) TestMustGetDuration(c *C) {
- input := "key = 123\nkey2 = ghi"
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGetDuration("key"), Equals, time.Duration(123))
- c.Assert(func() { p.MustGetDuration("key2") }, PanicMatches, "strconv.ParseInt: parsing.*")
- c.Assert(func() { p.MustGetDuration("invalid") }, PanicMatches, "unknown property: invalid")
-}
-
-func (s *TestSuite) TestGetParsedDuration(c *C) {
- for _, test := range parsedDurationTests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- c.Assert(p.Len(), Equals, 1)
- c.Assert(p.GetParsedDuration(test.key, test.def), Equals, test.value)
- }
-}
-
-func (s *TestSuite) TestMustGetParsedDuration(c *C) {
- input := "key = 123ms\nkey2 = ghi"
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGetParsedDuration("key"), Equals, 123*time.Millisecond)
- c.Assert(func() { p.MustGetParsedDuration("key2") }, PanicMatches, "time: invalid duration ghi")
- c.Assert(func() { p.MustGetParsedDuration("invalid") }, PanicMatches, "unknown property: invalid")
-}
-
-func (s *TestSuite) TestGetFloat64(c *C) {
- for _, test := range floatTests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- c.Assert(p.Len(), Equals, 1)
- c.Assert(p.GetFloat64(test.key, test.def), Equals, test.value)
- }
-}
-
-func (s *TestSuite) TestMustGetFloat64(c *C) {
- input := "key = 123\nkey2 = ghi"
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGetFloat64("key"), Equals, float64(123))
- c.Assert(func() { p.MustGetFloat64("key2") }, PanicMatches, "strconv.ParseFloat: parsing.*")
- c.Assert(func() { p.MustGetFloat64("invalid") }, PanicMatches, "unknown property: invalid")
-}
-
-func (s *TestSuite) TestGetInt(c *C) {
- for _, test := range int64Tests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- c.Assert(p.Len(), Equals, 1)
- c.Assert(p.GetInt(test.key, int(test.def)), Equals, int(test.value))
- }
-}
-
-func (s *TestSuite) TestMustGetInt(c *C) {
- input := "key = 123\nkey2 = ghi"
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGetInt("key"), Equals, int(123))
- c.Assert(func() { p.MustGetInt("key2") }, PanicMatches, "strconv.ParseInt: parsing.*")
- c.Assert(func() { p.MustGetInt("invalid") }, PanicMatches, "unknown property: invalid")
-}
-
-func (s *TestSuite) TestGetInt64(c *C) {
- for _, test := range int64Tests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- c.Assert(p.Len(), Equals, 1)
- c.Assert(p.GetInt64(test.key, test.def), Equals, test.value)
- }
-}
-
-func (s *TestSuite) TestMustGetInt64(c *C) {
- input := "key = 123\nkey2 = ghi"
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGetInt64("key"), Equals, int64(123))
- c.Assert(func() { p.MustGetInt64("key2") }, PanicMatches, "strconv.ParseInt: parsing.*")
- c.Assert(func() { p.MustGetInt64("invalid") }, PanicMatches, "unknown property: invalid")
-}
-
-func (s *TestSuite) TestGetUint(c *C) {
- for _, test := range uint64Tests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- c.Assert(p.Len(), Equals, 1)
- c.Assert(p.GetUint(test.key, uint(test.def)), Equals, uint(test.value))
- }
-}
-
-func (s *TestSuite) TestMustGetUint(c *C) {
- input := "key = 123\nkey2 = ghi"
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGetUint("key"), Equals, uint(123))
- c.Assert(func() { p.MustGetUint64("key2") }, PanicMatches, "strconv.ParseUint: parsing.*")
- c.Assert(func() { p.MustGetUint64("invalid") }, PanicMatches, "unknown property: invalid")
-}
-
-func (s *TestSuite) TestGetUint64(c *C) {
- for _, test := range uint64Tests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- c.Assert(p.Len(), Equals, 1)
- c.Assert(p.GetUint64(test.key, test.def), Equals, test.value)
- }
-}
-
-func (s *TestSuite) TestMustGetUint64(c *C) {
- input := "key = 123\nkey2 = ghi"
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGetUint64("key"), Equals, uint64(123))
- c.Assert(func() { p.MustGetUint64("key2") }, PanicMatches, "strconv.ParseUint: parsing.*")
- c.Assert(func() { p.MustGetUint64("invalid") }, PanicMatches, "unknown property: invalid")
-}
-
-func (s *TestSuite) TestGetString(c *C) {
- for _, test := range stringTests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- c.Assert(p.Len(), Equals, 1)
- c.Assert(p.GetString(test.key, test.def), Equals, test.value)
- }
-}
-
-func (s *TestSuite) TestMustGetString(c *C) {
- input := `key = value`
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGetString("key"), Equals, "value")
- c.Assert(func() { p.MustGetString("invalid") }, PanicMatches, "unknown property: invalid")
-}
-
-func (s *TestSuite) TestComment(c *C) {
- for _, test := range commentTests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGetString(test.key), Equals, test.value)
- c.Assert(p.GetComments(test.key), DeepEquals, test.comments)
- if test.comments != nil {
- c.Assert(p.GetComment(test.key), Equals, test.comments[len(test.comments)-1])
- } else {
- c.Assert(p.GetComment(test.key), Equals, "")
- }
-
- // test setting comments
- if len(test.comments) > 0 {
- // set single comment
- p.ClearComments()
- c.Assert(len(p.c), Equals, 0)
- p.SetComment(test.key, test.comments[0])
- c.Assert(p.GetComment(test.key), Equals, test.comments[0])
-
- // set multiple comments
- p.ClearComments()
- c.Assert(len(p.c), Equals, 0)
- p.SetComments(test.key, test.comments)
- c.Assert(p.GetComments(test.key), DeepEquals, test.comments)
-
- // clear comments for a key
- p.SetComments(test.key, nil)
- c.Assert(p.GetComment(test.key), Equals, "")
- c.Assert(p.GetComments(test.key), IsNil)
- }
- }
-}
-
-func (s *TestSuite) TestFilter(c *C) {
- for _, test := range filterTests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- pp, err := p.Filter(test.pattern)
- if err != nil {
- c.Assert(err, ErrorMatches, test.err)
- continue
- }
- c.Assert(pp, NotNil)
- c.Assert(pp.Len(), Equals, len(test.keys))
- for _, key := range test.keys {
- v1, ok1 := p.Get(key)
- v2, ok2 := pp.Get(key)
- c.Assert(ok1, Equals, true)
- c.Assert(ok2, Equals, true)
- c.Assert(v1, Equals, v2)
- }
- }
-}
-
-func (s *TestSuite) TestFilterPrefix(c *C) {
- for _, test := range filterPrefixTests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- pp := p.FilterPrefix(test.prefix)
- c.Assert(pp, NotNil)
- c.Assert(pp.Len(), Equals, len(test.keys))
- for _, key := range test.keys {
- v1, ok1 := p.Get(key)
- v2, ok2 := pp.Get(key)
- c.Assert(ok1, Equals, true)
- c.Assert(ok2, Equals, true)
- c.Assert(v1, Equals, v2)
- }
- }
-}
-
-func (s *TestSuite) TestKeys(c *C) {
- for _, test := range keysTests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- c.Assert(p.Len(), Equals, len(test.keys))
- c.Assert(len(p.Keys()), Equals, len(test.keys))
- c.Assert(p.Keys(), DeepEquals, test.keys)
- }
-}
-
-func (s *TestSuite) TestSet(c *C) {
- for _, test := range setTests {
- p, err := parse(test.input)
- c.Assert(err, IsNil)
- prev, ok, err := p.Set(test.key, test.value)
- if test.err != "" {
- c.Assert(err, ErrorMatches, test.err)
- continue
- }
-
- c.Assert(err, IsNil)
- c.Assert(ok, Equals, test.ok)
- if ok {
- c.Assert(prev, Equals, test.prev)
- }
- c.Assert(p.Keys(), DeepEquals, test.keys)
- }
-}
-
-func (s *TestSuite) TestMustSet(c *C) {
- input := "key=${key}"
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(func() { p.MustSet("key", "${key}") }, PanicMatches, "circular reference .*")
-}
-
-func (s *TestSuite) TestWrite(c *C) {
- for _, test := range writeTests {
- p, err := parse(test.input)
-
- buf := new(bytes.Buffer)
- var n int
- switch test.encoding {
- case "UTF-8":
- n, err = p.Write(buf, UTF8)
- case "ISO-8859-1":
- n, err = p.Write(buf, ISO_8859_1)
- }
- c.Assert(err, IsNil)
- s := string(buf.Bytes())
- c.Assert(n, Equals, len(test.output), Commentf("input=%q expected=%q obtained=%q", test.input, test.output, s))
- c.Assert(s, Equals, test.output, Commentf("input=%q expected=%q obtained=%q", test.input, test.output, s))
- }
-}
-
-func (s *TestSuite) TestWriteComment(c *C) {
- for _, test := range writeCommentTests {
- p, err := parse(test.input)
-
- buf := new(bytes.Buffer)
- var n int
- switch test.encoding {
- case "UTF-8":
- n, err = p.WriteComment(buf, "# ", UTF8)
- case "ISO-8859-1":
- n, err = p.WriteComment(buf, "# ", ISO_8859_1)
- }
- c.Assert(err, IsNil)
- s := string(buf.Bytes())
- c.Assert(n, Equals, len(test.output), Commentf("input=%q expected=%q obtained=%q", test.input, test.output, s))
- c.Assert(s, Equals, test.output, Commentf("input=%q expected=%q obtained=%q", test.input, test.output, s))
- }
-}
-
-func (s *TestSuite) TestCustomExpansionExpression(c *C) {
- testKeyValuePrePostfix(c, "*[", "]*", "key=value\nkey2=*[key]*", "key", "value", "key2", "value")
-}
-
-func (s *TestSuite) TestPanicOn32BitIntOverflow(c *C) {
- is32Bit = true
- var min, max int64 = math.MinInt32 - 1, math.MaxInt32 + 1
- input := fmt.Sprintf("min=%d\nmax=%d", min, max)
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGetInt64("min"), Equals, min)
- c.Assert(p.MustGetInt64("max"), Equals, max)
- c.Assert(func() { p.MustGetInt("min") }, PanicMatches, ".* out of range")
- c.Assert(func() { p.MustGetInt("max") }, PanicMatches, ".* out of range")
-}
-
-func (s *TestSuite) TestPanicOn32BitUintOverflow(c *C) {
- is32Bit = true
- var max = math.MaxUint32 + 1
- input := fmt.Sprintf("max=%d", max)
- p, err := parse(input)
- c.Assert(err, IsNil)
- c.Assert(p.MustGetUint64("max"), Equals, uint64(max))
- c.Assert(func() { p.MustGetUint("max") }, PanicMatches, ".* out of range")
-}
-
-// ----------------------------------------------------------------------------
-
-// tests all combinations of delimiters, leading and/or trailing whitespace and newlines.
-func testWhitespaceAndDelimiterCombinations(c *C, key, value string) {
- whitespace := []string{"", " ", "\f", "\t"}
- delimiters := []string{"", " ", "=", ":"}
- newlines := []string{"", "\r", "\n", "\r\n"}
- for _, dl := range delimiters {
- for _, ws1 := range whitespace {
- for _, ws2 := range whitespace {
- for _, nl := range newlines {
- // skip the one case where there is nothing between a key and a value
- if ws1 == "" && dl == "" && ws2 == "" && value != "" {
- continue
- }
-
- input := fmt.Sprintf("%s%s%s%s%s%s", key, ws1, dl, ws2, value, nl)
- testKeyValue(c, input, key, value)
- }
- }
- }
- }
-}
-
-// tests whether key/value pairs exist for a given input.
-// keyvalues is expected to be an even number of strings of "key", "value", ...
-func testKeyValue(c *C, input string, keyvalues ...string) {
- testKeyValuePrePostfix(c, "${", "}", input, keyvalues...)
-}
-
-// tests whether key/value pairs exist for a given input.
-// keyvalues is expected to be an even number of strings of "key", "value", ...
-func testKeyValuePrePostfix(c *C, prefix, postfix, input string, keyvalues ...string) {
- printf("%q\n", input)
-
- p, err := Load([]byte(input), ISO_8859_1)
- c.Assert(err, IsNil)
- p.Prefix = prefix
- p.Postfix = postfix
- assertKeyValues(c, input, p, keyvalues...)
-}
-
-// tests whether key/value pairs exist for a given input.
-// keyvalues is expected to be an even number of strings of "key", "value", ...
-func assertKeyValues(c *C, input string, p *Properties, keyvalues ...string) {
- c.Assert(p, NotNil)
- c.Assert(2*p.Len(), Equals, len(keyvalues), Commentf("Odd number of key/value pairs."))
-
- for i := 0; i < len(keyvalues); i += 2 {
- key, value := keyvalues[i], keyvalues[i+1]
- v, ok := p.Get(key)
- c.Assert(ok, Equals, true, Commentf("No key %q found (input=%q)", key, input))
- c.Assert(v, Equals, value, Commentf("Value %q does not match %q (input=%q)", v, value, input))
- }
-}
-
-// prints to stderr if the -verbose flag was given.
-func printf(format string, args ...interface{}) {
- if *verbose {
- fmt.Fprintf(os.Stderr, format, args...)
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/Godeps/_workspace/src/github.com/magiconair/properties/rangecheck.go
----------------------------------------------------------------------
diff --git a/Godeps/_workspace/src/github.com/magiconair/properties/rangecheck.go b/Godeps/_workspace/src/github.com/magiconair/properties/rangecheck.go
deleted file mode 100644
index 6df4e6c..0000000
--- a/Godeps/_workspace/src/github.com/magiconair/properties/rangecheck.go
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2013-2014 Frank Schroeder. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package properties
-
-import (
- "fmt"
- "math"
-)
-
-// make this a var to overwrite it in a test
-var is32Bit = ^uint(0) == math.MaxUint32
-
-// intRangeCheck checks if the value fits into the int type and
-// panics if it does not.
-func intRangeCheck(key string, v int64) int {
- if is32Bit && (v < math.MinInt32 || v > math.MaxInt32) {
- panic(fmt.Sprintf("Value %d for key %s out of range", v, key))
- }
- return int(v)
-}
-
-// uintRangeCheck checks if the value fits into the uint type and
-// panics if it does not.
-func uintRangeCheck(key string, v uint64) uint {
- if is32Bit && v > math.MaxUint32 {
- panic(fmt.Sprintf("Value %d for key %s out of range", v, key))
- }
- return uint(v)
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/Godeps/_workspace/src/github.com/mattn/go-sqlite3/.gitignore
----------------------------------------------------------------------
diff --git a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/.gitignore b/Godeps/_workspace/src/github.com/mattn/go-sqlite3/.gitignore
deleted file mode 100644
index bf90dfd..0000000
--- a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-*.db
-*.exe
-*.dll
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/Godeps/_workspace/src/github.com/mattn/go-sqlite3/.travis.yml
----------------------------------------------------------------------
diff --git a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/.travis.yml b/Godeps/_workspace/src/github.com/mattn/go-sqlite3/.travis.yml
deleted file mode 100644
index ac7bfea..0000000
--- a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/.travis.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-language: go
-go:
- - tip
-before_install:
- - go get github.com/axw/gocov/gocov
- - go get github.com/mattn/goveralls
- - go get golang.org/x/tools/cmd/cover
-script:
- - $HOME/gopath/bin/goveralls -repotoken 3qJVUE0iQwqnCbmNcDsjYu1nh4J4KIFXx
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/Godeps/_workspace/src/github.com/mattn/go-sqlite3/LICENSE
----------------------------------------------------------------------
diff --git a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/LICENSE b/Godeps/_workspace/src/github.com/mattn/go-sqlite3/LICENSE
deleted file mode 100644
index ca458bb..0000000
--- a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2014 Yasuhiro Matsumoto
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/Godeps/_workspace/src/github.com/mattn/go-sqlite3/README.md
----------------------------------------------------------------------
diff --git a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/README.md b/Godeps/_workspace/src/github.com/mattn/go-sqlite3/README.md
deleted file mode 100644
index 4383f0c..0000000
--- a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/README.md
+++ /dev/null
@@ -1,62 +0,0 @@
-go-sqlite3
-==========
-
-[![Build Status](https://travis-ci.org/mattn/go-sqlite3.png?branch=master)](https://travis-ci.org/mattn/go-sqlite3)
-[![Coverage Status](https://coveralls.io/repos/mattn/go-sqlite3/badge.png?branch=master)](https://coveralls.io/r/mattn/go-sqlite3?branch=master)
-
-Description
------------
-
-sqlite3 driver conforming to the built-in database/sql interface
-
-Installation
-------------
-
-This package can be installed with the go get command:
-
- go get github.com/mattn/go-sqlite3
-
-Documentation
--------------
-
-API documentation can be found here: http://godoc.org/github.com/mattn/go-sqlite3
-
-Examples can be found under the `./_example` directory
-
-FAQ
----
-
-* Can't build go-sqlite3 on windows 64bit.
-
- > Probably, you are using go 1.0, go1.0 has a problem when it comes to compiling/linking on windows 64bit.
- > See: https://github.com/mattn/go-sqlite3/issues/27
-
-* Getting insert error while query is opened.
-
- > You can pass some arguments into the connection string, for example, a URI.
- > See: https://github.com/mattn/go-sqlite3/issues/39
-
-* Do you want cross compiling? mingw on Linux or Mac?
-
- > See: https://github.com/mattn/go-sqlite3/issues/106
- > See also: http://www.limitlessfx.com/cross-compile-golang-app-for-windows-from-linux.html
-
-* Want to get time.Time with current locale
-
- Use `loc=auto` in SQLite3 filename schema like `file:foo.db?loc=auto`.
-
-License
--------
-
-MIT: http://mattn.mit-license.org/2012
-
-sqlite3-binding.c, sqlite3-binding.h, sqlite3ext.h
-
-The -binding suffix was added to avoid build failures under gccgo.
-
-In this repository, those files are amalgamation code that copied from SQLite3. The license of those codes are depend on the license of SQLite3.
-
-Author
-------
-
-Yasuhiro Matsumoto (a.k.a mattn)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/Godeps/_workspace/src/github.com/mattn/go-sqlite3/backup.go
----------------------------------------------------------------------
diff --git a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/backup.go b/Godeps/_workspace/src/github.com/mattn/go-sqlite3/backup.go
deleted file mode 100644
index 3807c60..0000000
--- a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/backup.go
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright (C) 2014 Yasuhiro Matsumoto <ma...@gmail.com>.
-//
-// Use of this source code is governed by an MIT-style
-// license that can be found in the LICENSE file.
-
-package sqlite3
-
-/*
-#include <sqlite3-binding.h>
-#include <stdlib.h>
-*/
-import "C"
-import (
- "runtime"
- "unsafe"
-)
-
-type SQLiteBackup struct {
- b *C.sqlite3_backup
-}
-
-func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*SQLiteBackup, error) {
- destptr := C.CString(dest)
- defer C.free(unsafe.Pointer(destptr))
- srcptr := C.CString(src)
- defer C.free(unsafe.Pointer(srcptr))
-
- if b := C.sqlite3_backup_init(c.db, destptr, conn.db, srcptr); b != nil {
- bb := &SQLiteBackup{b: b}
- runtime.SetFinalizer(bb, (*SQLiteBackup).Finish)
- return bb, nil
- }
- return nil, c.lastError()
-}
-
-// Backs up for one step. Calls the underlying `sqlite3_backup_step` function.
-// This function returns a boolean indicating if the backup is done and
-// an error signalling any other error. Done is returned if the underlying C
-// function returns SQLITE_DONE (Code 101)
-func (b *SQLiteBackup) Step(p int) (bool, error) {
- ret := C.sqlite3_backup_step(b.b, C.int(p))
- if ret == C.SQLITE_DONE {
- return true, nil
- } else if ret != 0 && ret != C.SQLITE_LOCKED && ret != C.SQLITE_BUSY {
- return false, Error{Code: ErrNo(ret)}
- }
- return false, nil
-}
-
-func (b *SQLiteBackup) Remaining() int {
- return int(C.sqlite3_backup_remaining(b.b))
-}
-
-func (b *SQLiteBackup) PageCount() int {
- return int(C.sqlite3_backup_pagecount(b.b))
-}
-
-func (b *SQLiteBackup) Finish() error {
- return b.Close()
-}
-
-func (b *SQLiteBackup) Close() error {
- ret := C.sqlite3_backup_finish(b.b)
- if ret != 0 {
- return Error{Code: ErrNo(ret)}
- }
- b.b = nil
- runtime.SetFinalizer(b, nil)
- return nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/Godeps/_workspace/src/github.com/mattn/go-sqlite3/doc.go
----------------------------------------------------------------------
diff --git a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/doc.go b/Godeps/_workspace/src/github.com/mattn/go-sqlite3/doc.go
deleted file mode 100644
index 51364c3..0000000
--- a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/doc.go
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
-Package sqlite3 provides interface to SQLite3 databases.
-
-This works as driver for database/sql.
-
-Installation
-
- go get github.com/mattn/go-sqlite3
-
-Supported Types
-
-Currently, go-sqlite3 support following data types.
-
- +------------------------------+
- |go | sqlite3 |
- |----------|-------------------|
- |nil | null |
- |int | integer |
- |int64 | integer |
- |float64 | float |
- |bool | integer |
- |[]byte | blob |
- |string | text |
- |time.Time | timestamp/datetime|
- +------------------------------+
-
-SQLite3 Extension
-
-You can write your own extension module for sqlite3. For example, below is a
-extension for Regexp matcher operation.
-
- #include <pcre.h>
- #include <string.h>
- #include <stdio.h>
- #include <sqlite3ext.h>
-
- SQLITE_EXTENSION_INIT1
- static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) {
- if (argc >= 2) {
- const char *target = (const char *)sqlite3_value_text(argv[1]);
- const char *pattern = (const char *)sqlite3_value_text(argv[0]);
- const char* errstr = NULL;
- int erroff = 0;
- int vec[500];
- int n, rc;
- pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL);
- rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500);
- if (rc <= 0) {
- sqlite3_result_error(context, errstr, 0);
- return;
- }
- sqlite3_result_int(context, 1);
- }
- }
-
- #ifdef _WIN32
- __declspec(dllexport)
- #endif
- int sqlite3_extension_init(sqlite3 *db, char **errmsg,
- const sqlite3_api_routines *api) {
- SQLITE_EXTENSION_INIT2(api);
- return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8,
- (void*)db, regexp_func, NULL, NULL);
- }
-
-It need to build as so/dll shared library. And you need to register
-extension module like below.
-
- sql.Register("sqlite3_with_extensions",
- &sqlite3.SQLiteDriver{
- Extensions: []string{
- "sqlite3_mod_regexp",
- },
- })
-
-Then, you can use this extension.
-
- rows, err := db.Query("select text from mytable where name regexp '^golang'")
-
-Connection Hook
-
-You can hook and inject your codes when connection established. database/sql
-doesn't provide the way to get native go-sqlite3 interfaces. So if you want,
-you need to hook ConnectHook and get the SQLiteConn.
-
- sql.Register("sqlite3_with_hook_example",
- &sqlite3.SQLiteDriver{
- ConnectHook: func(conn *sqlite3.SQLiteConn) error {
- sqlite3conn = append(sqlite3conn, conn)
- return nil
- },
- })
-
-*/
-package sqlite3
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error.go
----------------------------------------------------------------------
diff --git a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error.go b/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error.go
deleted file mode 100644
index b910108..0000000
--- a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error.go
+++ /dev/null
@@ -1,128 +0,0 @@
-// Copyright (C) 2014 Yasuhiro Matsumoto <ma...@gmail.com>.
-//
-// Use of this source code is governed by an MIT-style
-// license that can be found in the LICENSE file.
-
-package sqlite3
-
-import "C"
-
-type ErrNo int
-
-const ErrNoMask C.int = 0xff
-
-type ErrNoExtended int
-
-type Error struct {
- Code ErrNo /* The error code returned by SQLite */
- ExtendedCode ErrNoExtended /* The extended error code returned by SQLite */
- err string /* The error string returned by sqlite3_errmsg(),
- this usually contains more specific details. */
-}
-
-// result codes from http://www.sqlite.org/c3ref/c_abort.html
-var (
- ErrError = ErrNo(1) /* SQL error or missing database */
- ErrInternal = ErrNo(2) /* Internal logic error in SQLite */
- ErrPerm = ErrNo(3) /* Access permission denied */
- ErrAbort = ErrNo(4) /* Callback routine requested an abort */
- ErrBusy = ErrNo(5) /* The database file is locked */
- ErrLocked = ErrNo(6) /* A table in the database is locked */
- ErrNomem = ErrNo(7) /* A malloc() failed */
- ErrReadonly = ErrNo(8) /* Attempt to write a readonly database */
- ErrInterrupt = ErrNo(9) /* Operation terminated by sqlite3_interrupt() */
- ErrIoErr = ErrNo(10) /* Some kind of disk I/O error occurred */
- ErrCorrupt = ErrNo(11) /* The database disk image is malformed */
- ErrNotFound = ErrNo(12) /* Unknown opcode in sqlite3_file_control() */
- ErrFull = ErrNo(13) /* Insertion failed because database is full */
- ErrCantOpen = ErrNo(14) /* Unable to open the database file */
- ErrProtocol = ErrNo(15) /* Database lock protocol error */
- ErrEmpty = ErrNo(16) /* Database is empty */
- ErrSchema = ErrNo(17) /* The database schema changed */
- ErrTooBig = ErrNo(18) /* String or BLOB exceeds size limit */
- ErrConstraint = ErrNo(19) /* Abort due to constraint violation */
- ErrMismatch = ErrNo(20) /* Data type mismatch */
- ErrMisuse = ErrNo(21) /* Library used incorrectly */
- ErrNoLFS = ErrNo(22) /* Uses OS features not supported on host */
- ErrAuth = ErrNo(23) /* Authorization denied */
- ErrFormat = ErrNo(24) /* Auxiliary database format error */
- ErrRange = ErrNo(25) /* 2nd parameter to sqlite3_bind out of range */
- ErrNotADB = ErrNo(26) /* File opened that is not a database file */
- ErrNotice = ErrNo(27) /* Notifications from sqlite3_log() */
- ErrWarning = ErrNo(28) /* Warnings from sqlite3_log() */
-)
-
-func (err ErrNo) Error() string {
- return Error{Code: err}.Error()
-}
-
-func (err ErrNo) Extend(by int) ErrNoExtended {
- return ErrNoExtended(int(err) | (by << 8))
-}
-
-func (err ErrNoExtended) Error() string {
- return Error{Code: ErrNo(C.int(err) & ErrNoMask), ExtendedCode: err}.Error()
-}
-
-func (err Error) Error() string {
- if err.err != "" {
- return err.err
- }
- return errorString(err)
-}
-
-// result codes from http://www.sqlite.org/c3ref/c_abort_rollback.html
-var (
- ErrIoErrRead = ErrIoErr.Extend(1)
- ErrIoErrShortRead = ErrIoErr.Extend(2)
- ErrIoErrWrite = ErrIoErr.Extend(3)
- ErrIoErrFsync = ErrIoErr.Extend(4)
- ErrIoErrDirFsync = ErrIoErr.Extend(5)
- ErrIoErrTruncate = ErrIoErr.Extend(6)
- ErrIoErrFstat = ErrIoErr.Extend(7)
- ErrIoErrUnlock = ErrIoErr.Extend(8)
- ErrIoErrRDlock = ErrIoErr.Extend(9)
- ErrIoErrDelete = ErrIoErr.Extend(10)
- ErrIoErrBlocked = ErrIoErr.Extend(11)
- ErrIoErrNoMem = ErrIoErr.Extend(12)
- ErrIoErrAccess = ErrIoErr.Extend(13)
- ErrIoErrCheckReservedLock = ErrIoErr.Extend(14)
- ErrIoErrLock = ErrIoErr.Extend(15)
- ErrIoErrClose = ErrIoErr.Extend(16)
- ErrIoErrDirClose = ErrIoErr.Extend(17)
- ErrIoErrSHMOpen = ErrIoErr.Extend(18)
- ErrIoErrSHMSize = ErrIoErr.Extend(19)
- ErrIoErrSHMLock = ErrIoErr.Extend(20)
- ErrIoErrSHMMap = ErrIoErr.Extend(21)
- ErrIoErrSeek = ErrIoErr.Extend(22)
- ErrIoErrDeleteNoent = ErrIoErr.Extend(23)
- ErrIoErrMMap = ErrIoErr.Extend(24)
- ErrIoErrGetTempPath = ErrIoErr.Extend(25)
- ErrIoErrConvPath = ErrIoErr.Extend(26)
- ErrLockedSharedCache = ErrLocked.Extend(1)
- ErrBusyRecovery = ErrBusy.Extend(1)
- ErrBusySnapshot = ErrBusy.Extend(2)
- ErrCantOpenNoTempDir = ErrCantOpen.Extend(1)
- ErrCantOpenIsDir = ErrCantOpen.Extend(2)
- ErrCantOpenFullPath = ErrCantOpen.Extend(3)
- ErrCantOpenConvPath = ErrCantOpen.Extend(4)
- ErrCorruptVTab = ErrCorrupt.Extend(1)
- ErrReadonlyRecovery = ErrReadonly.Extend(1)
- ErrReadonlyCantLock = ErrReadonly.Extend(2)
- ErrReadonlyRollback = ErrReadonly.Extend(3)
- ErrReadonlyDbMoved = ErrReadonly.Extend(4)
- ErrAbortRollback = ErrAbort.Extend(2)
- ErrConstraintCheck = ErrConstraint.Extend(1)
- ErrConstraintCommitHook = ErrConstraint.Extend(2)
- ErrConstraintForeignKey = ErrConstraint.Extend(3)
- ErrConstraintFunction = ErrConstraint.Extend(4)
- ErrConstraintNotNull = ErrConstraint.Extend(5)
- ErrConstraintPrimaryKey = ErrConstraint.Extend(6)
- ErrConstraintTrigger = ErrConstraint.Extend(7)
- ErrConstraintUnique = ErrConstraint.Extend(8)
- ErrConstraintVTab = ErrConstraint.Extend(9)
- ErrConstraintRowId = ErrConstraint.Extend(10)
- ErrNoticeRecoverWAL = ErrNotice.Extend(1)
- ErrNoticeRecoverRollback = ErrNotice.Extend(2)
- ErrWarningAutoIndex = ErrWarning.Extend(1)
-)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/e95057f4/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error_test.go
----------------------------------------------------------------------
diff --git a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error_test.go b/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error_test.go
deleted file mode 100644
index 1ccbe5b..0000000
--- a/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error_test.go
+++ /dev/null
@@ -1,242 +0,0 @@
-// Copyright (C) 2014 Yasuhiro Matsumoto <ma...@gmail.com>.
-//
-// Use of this source code is governed by an MIT-style
-// license that can be found in the LICENSE file.
-
-package sqlite3
-
-import (
- "database/sql"
- "io/ioutil"
- "os"
- "path"
- "testing"
-)
-
-func TestSimpleError(t *testing.T) {
- e := ErrError.Error()
- if e != "SQL logic error or missing database" {
- t.Error("wrong error code:" + e)
- }
-}
-
-func TestCorruptDbErrors(t *testing.T) {
- dirName, err := ioutil.TempDir("", "sqlite3")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(dirName)
-
- dbFileName := path.Join(dirName, "test.db")
- f, err := os.Create(dbFileName)
- if err != nil {
- t.Error(err)
- }
- f.Write([]byte{1, 2, 3, 4, 5})
- f.Close()
-
- db, err := sql.Open("sqlite3", dbFileName)
- if err == nil {
- _, err = db.Exec("drop table foo")
- }
-
- sqliteErr := err.(Error)
- if sqliteErr.Code != ErrNotADB {
- t.Error("wrong error code for corrupted DB")
- }
- if err.Error() == "" {
- t.Error("wrong error string for corrupted DB")
- }
- db.Close()
-}
-
-func TestSqlLogicErrors(t *testing.T) {
- dirName, err := ioutil.TempDir("", "sqlite3")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(dirName)
-
- dbFileName := path.Join(dirName, "test.db")
- db, err := sql.Open("sqlite3", dbFileName)
- if err != nil {
- t.Error(err)
- }
- defer db.Close()
-
- _, err = db.Exec("CREATE TABLE Foo (id INTEGER PRIMARY KEY)")
- if err != nil {
- t.Error(err)
- }
-
- const expectedErr = "table Foo already exists"
- _, err = db.Exec("CREATE TABLE Foo (id INTEGER PRIMARY KEY)")
- if err.Error() != expectedErr {
- t.Errorf("Unexpected error: %s, expected %s", err.Error(), expectedErr)
- }
-
-}
-
-func TestExtendedErrorCodes_ForeignKey(t *testing.T) {
- dirName, err := ioutil.TempDir("", "sqlite3-err")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(dirName)
-
- dbFileName := path.Join(dirName, "test.db")
- db, err := sql.Open("sqlite3", dbFileName)
- if err != nil {
- t.Error(err)
- }
- defer db.Close()
-
- _, err = db.Exec("PRAGMA foreign_keys=ON;")
- if err != nil {
- t.Errorf("PRAGMA foreign_keys=ON: %v", err)
- }
-
- _, err = db.Exec(`CREATE TABLE Foo (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- value INTEGER NOT NULL,
- ref INTEGER NULL REFERENCES Foo (id),
- UNIQUE(value)
- );`)
- if err != nil {
- t.Error(err)
- }
-
- _, err = db.Exec("INSERT INTO Foo (ref, value) VALUES (100, 100);")
- if err == nil {
- t.Error("No error!")
- } else {
- sqliteErr := err.(Error)
- if sqliteErr.Code != ErrConstraint {
- t.Errorf("Wrong basic error code: %d != %d",
- sqliteErr.Code, ErrConstraint)
- }
- if sqliteErr.ExtendedCode != ErrConstraintForeignKey {
- t.Errorf("Wrong extended error code: %d != %d",
- sqliteErr.ExtendedCode, ErrConstraintForeignKey)
- }
- }
-
-}
-
-func TestExtendedErrorCodes_NotNull(t *testing.T) {
- dirName, err := ioutil.TempDir("", "sqlite3-err")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(dirName)
-
- dbFileName := path.Join(dirName, "test.db")
- db, err := sql.Open("sqlite3", dbFileName)
- if err != nil {
- t.Error(err)
- }
- defer db.Close()
-
- _, err = db.Exec("PRAGMA foreign_keys=ON;")
- if err != nil {
- t.Errorf("PRAGMA foreign_keys=ON: %v", err)
- }
-
- _, err = db.Exec(`CREATE TABLE Foo (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- value INTEGER NOT NULL,
- ref INTEGER NULL REFERENCES Foo (id),
- UNIQUE(value)
- );`)
- if err != nil {
- t.Error(err)
- }
-
- res, err := db.Exec("INSERT INTO Foo (value) VALUES (100);")
- if err != nil {
- t.Fatalf("Creating first row: %v", err)
- }
-
- id, err := res.LastInsertId()
- if err != nil {
- t.Fatalf("Retrieving last insert id: %v", err)
- }
-
- _, err = db.Exec("INSERT INTO Foo (ref) VALUES (?);", id)
- if err == nil {
- t.Error("No error!")
- } else {
- sqliteErr := err.(Error)
- if sqliteErr.Code != ErrConstraint {
- t.Errorf("Wrong basic error code: %d != %d",
- sqliteErr.Code, ErrConstraint)
- }
- if sqliteErr.ExtendedCode != ErrConstraintNotNull {
- t.Errorf("Wrong extended error code: %d != %d",
- sqliteErr.ExtendedCode, ErrConstraintNotNull)
- }
- }
-
-}
-
-func TestExtendedErrorCodes_Unique(t *testing.T) {
- dirName, err := ioutil.TempDir("", "sqlite3-err")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(dirName)
-
- dbFileName := path.Join(dirName, "test.db")
- db, err := sql.Open("sqlite3", dbFileName)
- if err != nil {
- t.Error(err)
- }
- defer db.Close()
-
- _, err = db.Exec("PRAGMA foreign_keys=ON;")
- if err != nil {
- t.Errorf("PRAGMA foreign_keys=ON: %v", err)
- }
-
- _, err = db.Exec(`CREATE TABLE Foo (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- value INTEGER NOT NULL,
- ref INTEGER NULL REFERENCES Foo (id),
- UNIQUE(value)
- );`)
- if err != nil {
- t.Error(err)
- }
-
- res, err := db.Exec("INSERT INTO Foo (value) VALUES (100);")
- if err != nil {
- t.Fatalf("Creating first row: %v", err)
- }
-
- id, err := res.LastInsertId()
- if err != nil {
- t.Fatalf("Retrieving last insert id: %v", err)
- }
-
- _, err = db.Exec("INSERT INTO Foo (ref, value) VALUES (?, 100);", id)
- if err == nil {
- t.Error("No error!")
- } else {
- sqliteErr := err.(Error)
- if sqliteErr.Code != ErrConstraint {
- t.Errorf("Wrong basic error code: %d != %d",
- sqliteErr.Code, ErrConstraint)
- }
- if sqliteErr.ExtendedCode != ErrConstraintUnique {
- t.Errorf("Wrong extended error code: %d != %d",
- sqliteErr.ExtendedCode, ErrConstraintUnique)
- }
- extended := sqliteErr.Code.Extend(3).Error()
- expected := "constraint failed"
- if extended != expected {
- t.Errorf("Wrong basic error code: %q != %q",
- extended, expected)
- }
- }
-
-}