├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── cmd └── summitdb-server │ └── main.go ├── machine ├── all_test.go ├── do.go ├── indexes.go ├── indexes_test.go ├── iter.go ├── json.go ├── json_test.go ├── keys.go ├── keys_test.go ├── machine.go ├── mock_test.go ├── multi.go ├── raft_test.go ├── script.go ├── scripts_test.go ├── server.go ├── snapshot.go ├── spatial.go ├── strings.go ├── strings_test.go ├── transactions_test.go └── utils.go ├── resources ├── build.sh ├── logo.png └── vendor.sh └── vendor ├── github.com ├── armon │ └── go-metrics │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── README.md │ │ ├── circonus │ │ ├── circonus.go │ │ └── circonus_test.go │ │ ├── const_unix.go │ │ ├── const_windows.go │ │ ├── datadog │ │ ├── dogstatsd.go │ │ └── dogstatsd_test.go │ │ ├── inmem.go │ │ ├── inmem_signal.go │ │ ├── inmem_signal_test.go │ │ ├── inmem_test.go │ │ ├── metrics.go │ │ ├── metrics_test.go │ │ ├── prometheus │ │ └── prometheus.go │ │ ├── sink.go │ │ ├── sink_test.go │ │ ├── start.go │ │ ├── start_test.go │ │ ├── statsd.go │ │ ├── statsd_test.go │ │ ├── statsite.go │ │ └── statsite_test.go ├── boltdb │ └── bolt │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── appveyor.yml │ │ ├── bolt_386.go │ │ ├── bolt_amd64.go │ │ ├── bolt_arm.go │ │ ├── bolt_arm64.go │ │ ├── bolt_linux.go │ │ ├── bolt_openbsd.go │ │ ├── bolt_ppc.go │ │ ├── bolt_ppc64.go │ │ ├── bolt_ppc64le.go │ │ ├── bolt_s390x.go │ │ ├── bolt_unix.go │ │ ├── bolt_unix_solaris.go │ │ ├── bolt_windows.go │ │ ├── boltsync_unix.go │ │ ├── bucket.go │ │ ├── bucket_test.go │ │ ├── cmd │ │ └── bolt │ │ │ ├── main.go │ │ │ └── main_test.go │ │ ├── cursor.go │ │ ├── cursor_test.go │ │ ├── db.go │ │ ├── db_test.go │ │ ├── doc.go │ │ ├── errors.go │ │ ├── freelist.go │ │ ├── freelist_test.go │ │ ├── node.go │ │ ├── node_test.go │ │ ├── page.go │ │ ├── page_test.go │ │ ├── quick_test.go │ │ ├── simulation_test.go │ │ ├── tx.go │ │ └── tx_test.go ├── garyburd │ └── redigo │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.markdown │ │ ├── internal │ │ ├── commandinfo.go │ │ ├── commandinfo_test.go │ │ └── redistest │ │ │ └── testdb.go │ │ ├── redis │ │ ├── conn.go │ │ ├── conn_test.go │ │ ├── doc.go │ │ ├── log.go │ │ ├── pool.go │ │ ├── pool_test.go │ │ ├── pubsub.go │ │ ├── pubsub_test.go │ │ ├── redis.go │ │ ├── reply.go │ │ ├── reply_test.go │ │ ├── scan.go │ │ ├── scan_test.go │ │ ├── script.go │ │ ├── script_test.go │ │ ├── test_test.go │ │ └── zpop_example_test.go │ │ └── redisx │ │ ├── connmux.go │ │ ├── connmux_test.go │ │ └── doc.go ├── hashicorp │ ├── go-msgpack │ │ └── codec │ │ │ ├── 0doc.go │ │ │ ├── README.md │ │ │ ├── bench_test.go │ │ │ ├── binc.go │ │ │ ├── codecs_test.go │ │ │ ├── decode.go │ │ │ ├── encode.go │ │ │ ├── ext_dep_test.go │ │ │ ├── helper.go │ │ │ ├── helper_internal.go │ │ │ ├── msgpack.go │ │ │ ├── msgpack_test.py │ │ │ ├── rpc.go │ │ │ ├── simple.go │ │ │ ├── time.go │ │ │ └── z_helper_test.go │ └── raft │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── bench │ │ └── bench.go │ │ ├── commands.go │ │ ├── config.go │ │ ├── discard_snapshot.go │ │ ├── discard_snapshot_test.go │ │ ├── file_snapshot.go │ │ ├── file_snapshot_test.go │ │ ├── fsm.go │ │ ├── future.go │ │ ├── future_test.go │ │ ├── inflight.go │ │ ├── inflight_test.go │ │ ├── inmem_store.go │ │ ├── inmem_transport.go │ │ ├── inmem_transport_test.go │ │ ├── integ_test.go │ │ ├── log.go │ │ ├── log_cache.go │ │ ├── log_cache_test.go │ │ ├── net_transport.go │ │ ├── net_transport_test.go │ │ ├── observer.go │ │ ├── peer.go │ │ ├── peer_test.go │ │ ├── raft.go │ │ ├── raft_test.go │ │ ├── replication.go │ │ ├── snapshot.go │ │ ├── stable.go │ │ ├── state.go │ │ ├── tcp_transport.go │ │ ├── tcp_transport_test.go │ │ ├── transport.go │ │ ├── transport_test.go │ │ ├── util.go │ │ └── util_test.go ├── robertkrimen │ └── otto │ │ ├── .gitignore │ │ ├── DESIGN.markdown │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.markdown │ │ ├── array_test.go │ │ ├── ast │ │ ├── README.markdown │ │ ├── comments.go │ │ ├── comments_test.go │ │ └── node.go │ │ ├── bug_test.go │ │ ├── builtin.go │ │ ├── builtin_array.go │ │ ├── builtin_boolean.go │ │ ├── builtin_date.go │ │ ├── builtin_error.go │ │ ├── builtin_function.go │ │ ├── builtin_json.go │ │ ├── builtin_math.go │ │ ├── builtin_number.go │ │ ├── builtin_object.go │ │ ├── builtin_regexp.go │ │ ├── builtin_string.go │ │ ├── builtin_test.go │ │ ├── call_test.go │ │ ├── clone.go │ │ ├── clone_test.go │ │ ├── cmpl.go │ │ ├── cmpl_evaluate.go │ │ ├── cmpl_evaluate_expression.go │ │ ├── cmpl_evaluate_statement.go │ │ ├── cmpl_parse.go │ │ ├── cmpl_test.go │ │ ├── console.go │ │ ├── date_test.go │ │ ├── dbg.go │ │ ├── dbg │ │ └── dbg.go │ │ ├── documentation_test.go │ │ ├── error.go │ │ ├── error_native_test.go │ │ ├── error_test.go │ │ ├── evaluate.go │ │ ├── file │ │ ├── README.markdown │ │ └── file.go │ │ ├── function_stack_test.go │ │ ├── function_test.go │ │ ├── global.go │ │ ├── global_test.go │ │ ├── inline.go │ │ ├── inline.pl │ │ ├── json_test.go │ │ ├── math_test.go │ │ ├── native_stack_test.go │ │ ├── number_test.go │ │ ├── object.go │ │ ├── object_class.go │ │ ├── object_test.go │ │ ├── otto.go │ │ ├── otto │ │ ├── Makefile │ │ └── main.go │ │ ├── otto_.go │ │ ├── otto_error_test.go │ │ ├── otto_test.go │ │ ├── panic_test.go │ │ ├── parser │ │ ├── Makefile │ │ ├── README.markdown │ │ ├── comments_test.go │ │ ├── dbg.go │ │ ├── error.go │ │ ├── expression.go │ │ ├── lexer.go │ │ ├── lexer_test.go │ │ ├── marshal_test.go │ │ ├── parser.go │ │ ├── parser_test.go │ │ ├── regexp.go │ │ ├── regexp_test.go │ │ ├── scope.go │ │ └── statement.go │ │ ├── parser_test.go │ │ ├── property.go │ │ ├── reflect_test.go │ │ ├── regexp_test.go │ │ ├── registry │ │ ├── README.markdown │ │ └── registry.go │ │ ├── repl │ │ ├── autocompleter.go │ │ └── repl.go │ │ ├── result.go │ │ ├── runtime.go │ │ ├── runtime_test.go │ │ ├── scope.go │ │ ├── script.go │ │ ├── script_test.go │ │ ├── sourcemap_test.go │ │ ├── stash.go │ │ ├── string_test.go │ │ ├── terst │ │ └── terst.go │ │ ├── test │ │ ├── Makefile │ │ └── tester.go │ │ ├── testing_test.go │ │ ├── token │ │ ├── Makefile │ │ ├── README.markdown │ │ ├── token.go │ │ ├── token_const.go │ │ └── tokenfmt │ │ ├── type_arguments.go │ │ ├── type_array.go │ │ ├── type_boolean.go │ │ ├── type_date.go │ │ ├── type_error.go │ │ ├── type_function.go │ │ ├── type_go_array.go │ │ ├── type_go_map.go │ │ ├── type_go_slice.go │ │ ├── type_go_slice_test.go │ │ ├── type_go_struct.go │ │ ├── type_number.go │ │ ├── type_reference.go │ │ ├── type_regexp.go │ │ ├── type_string.go │ │ ├── underscore │ │ ├── Makefile │ │ ├── README.markdown │ │ ├── source.go │ │ ├── testify │ │ └── underscore.go │ │ ├── underscore_arrays_test.go │ │ ├── underscore_chaining_test.go │ │ ├── underscore_collections_test.go │ │ ├── underscore_functions_test.go │ │ ├── underscore_objects_test.go │ │ ├── underscore_test.go │ │ ├── underscore_utility_test.go │ │ ├── value.go │ │ ├── value_boolean.go │ │ ├── value_number.go │ │ ├── value_primitive.go │ │ ├── value_string.go │ │ └── value_test.go └── tidwall │ ├── btree │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── btree.go │ └── btree_test.go │ ├── buntdb │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── buntdb.go │ ├── buntdb_test.go │ └── logo.png │ ├── collate │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── collate.go │ └── collate_test.go │ ├── finn │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── example │ │ └── clone.go │ ├── finn.go │ ├── finn_test.go │ └── logo.jpg │ ├── gjson │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── gjson.go │ ├── gjson_test.go │ └── logo.png │ ├── grect │ ├── LICENSE.md │ ├── README.md │ ├── grect.go │ └── grect_test.go │ ├── less │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── less.go │ └── less_test.go │ ├── match │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── match.go │ └── match_test.go │ ├── raft-boltdb │ ├── LICENSE │ ├── README.md │ ├── bench_test.go │ ├── bolt_store.go │ ├── bolt_store_test.go │ └── util.go │ ├── raft-fastlog │ ├── LICENSE │ ├── README.md │ ├── bench_test.go │ ├── store.go │ └── store_test.go │ ├── raft-redcon │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── transport.go │ └── transport_test.go │ ├── redcon │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── example │ │ └── clone.go │ ├── logo.png │ ├── redcon.go │ └── redcon_test.go │ ├── redlog │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── redlog.go │ └── redlog_test.go │ ├── rtree │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── gen │ │ ├── gen.go │ │ ├── gen.sh │ │ └── src │ │ │ ├── rtree.go │ │ │ └── rtree_base.go │ ├── rtree.go │ └── rtree_test.go │ └── sjson │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── logo.png │ ├── sjson.go │ └── sjson_test.go ├── golang.org └── x │ ├── crypto │ └── ssh │ │ └── terminal │ │ ├── terminal.go │ │ ├── terminal_test.go │ │ ├── util.go │ │ ├── util_bsd.go │ │ ├── util_linux.go │ │ ├── util_plan9.go │ │ ├── util_solaris.go │ │ └── util_windows.go │ └── text │ ├── collate │ ├── build │ │ ├── builder.go │ │ ├── builder_test.go │ │ ├── colelem.go │ │ ├── colelem_test.go │ │ ├── contract.go │ │ ├── contract_test.go │ │ ├── order.go │ │ ├── order_test.go │ │ ├── table.go │ │ ├── trie.go │ │ └── trie_test.go │ ├── collate.go │ ├── collate_test.go │ ├── export_test.go │ ├── index.go │ ├── maketables.go │ ├── option.go │ ├── option_test.go │ ├── reg_test.go │ ├── sort.go │ ├── sort_test.go │ ├── table_test.go │ ├── tables.go │ └── tools │ │ └── colcmp │ │ ├── Makefile │ │ ├── chars.go │ │ ├── col.go │ │ ├── colcmp.go │ │ ├── darwin.go │ │ ├── gen.go │ │ └── icu.go │ ├── internal │ ├── colltab │ │ ├── collate_test.go │ │ ├── collelem.go │ │ ├── collelem_test.go │ │ ├── colltab.go │ │ ├── colltab_test.go │ │ ├── contract.go │ │ ├── contract_test.go │ │ ├── iter.go │ │ ├── iter_test.go │ │ ├── numeric.go │ │ ├── numeric_test.go │ │ ├── table.go │ │ ├── trie.go │ │ ├── trie_test.go │ │ ├── weighter.go │ │ └── weighter_test.go │ └── tag │ │ ├── tag.go │ │ └── tag_test.go │ ├── language │ ├── Makefile │ ├── common.go │ ├── coverage.go │ ├── coverage_test.go │ ├── data_test.go │ ├── display │ │ ├── dict.go │ │ ├── dict_test.go │ │ ├── display.go │ │ ├── display_test.go │ │ ├── examples_test.go │ │ ├── lookup.go │ │ ├── maketables.go │ │ └── tables.go │ ├── examples_test.go │ ├── gen_common.go │ ├── gen_index.go │ ├── go1_1.go │ ├── go1_2.go │ ├── httpexample_test.go │ ├── index.go │ ├── language.go │ ├── language_test.go │ ├── lookup.go │ ├── lookup_test.go │ ├── maketables.go │ ├── match.go │ ├── match_test.go │ ├── parse.go │ ├── parse_test.go │ ├── tables.go │ └── tags.go │ ├── transform │ ├── examples_test.go │ ├── transform.go │ └── transform_test.go │ └── unicode │ └── norm │ ├── composition.go │ ├── composition_test.go │ ├── example_iter_test.go │ ├── example_test.go │ ├── forminfo.go │ ├── forminfo_test.go │ ├── input.go │ ├── iter.go │ ├── iter_test.go │ ├── maketables.go │ ├── norm_test.go │ ├── normalize.go │ ├── normalize_test.go │ ├── readwriter.go │ ├── readwriter_test.go │ ├── tables.go │ ├── transform.go │ ├── transform_test.go │ ├── trie.go │ ├── triegen.go │ └── ucd_test.go └── gopkg.in └── sourcemap.v1 ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── base64vlq ├── base64_vlq.go └── base64_vlq_test.go ├── consumer.go ├── consumer_test.go └── example_test.go /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | This project adheres to [Semantic Versioning](http://semver.org/). 4 | 5 | ## [0.4.0] - 2017-02-02 6 | ### Added 7 | - #10: FENCEGET command for reading fencing token without changing it (@glycerine) 8 | - Length option to FENCE command, supports batch updates (@glycerine) 9 | 10 | ### Fixed 11 | - Redcon memory leak 12 | 13 | ## [0.3.2] - 2016-10-17 14 | ### Added 15 | - JSET, JGET, JDEL commands for working with JSON documents. 16 | 17 | ### Changed 18 | - Moved build.sh into resources direction to avoid confusion about 19 | which to use: build.sh or make. 20 | - Updated GJSON/SJSON vendored libraries. 21 | 22 | ## [0.2.2] - 2016-10-17 23 | ### Added 24 | - Added BACKUP command 25 | - Added RAFTPEERS command 26 | - Added FENCE command 27 | 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Josh Baker 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | Contact GitHub API Training Shop Blog About 21 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | @resources/build.sh 3 | clean: 4 | @rm -f summitdb-server 5 | @rm -rf redis-3.2.4 6 | @rm -f redis-cli 7 | .PHONY: test 8 | test: 9 | @cd machine && go test 10 | install: all 11 | @cp summitdb-server /usr/local/bin 12 | uninstall: 13 | @rm -f /usr/local/bin/summitdb-server 14 | redis-cli: 15 | @rm -rf redis-3.2.4 && \ 16 | curl http://download.redis.io/releases/redis-3.2.4.tar.gz | tar xz && \ 17 | cd redis-3.2.4 && \ 18 | make redis-cli && \ 19 | cp src/redis-cli .. && \ 20 | cd .. && \ 21 | rm -rf redis-3.2.4 22 | package: 23 | @NOCOPY=1 resources/build.sh package 24 | -------------------------------------------------------------------------------- /machine/all_test.go: -------------------------------------------------------------------------------- 1 | package machine 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "os/signal" 7 | "syscall" 8 | "testing" 9 | ) 10 | 11 | const ( 12 | clear = "\x1b[0m" 13 | bright = "\x1b[1m" 14 | dim = "\x1b[2m" 15 | black = "\x1b[30m" 16 | red = "\x1b[31m" 17 | green = "\x1b[32m" 18 | yellow = "\x1b[33m" 19 | blue = "\x1b[34m" 20 | magenta = "\x1b[35m" 21 | cyan = "\x1b[36m" 22 | white = "\x1b[37m" 23 | ) 24 | 25 | func TestAll(t *testing.T) { 26 | mockCleanup() 27 | defer mockCleanup() 28 | 29 | ch := make(chan os.Signal) 30 | signal.Notify(ch, os.Interrupt, syscall.SIGTERM) 31 | go func() { 32 | <-ch 33 | mockCleanup() 34 | os.Exit(1) 35 | }() 36 | 37 | mc, err := mockOpenCluster(3) 38 | if err != nil { 39 | t.Fatal(err) 40 | } 41 | defer mc.Close() 42 | runSubTest(t, "strings", mc, subTestStrings) 43 | runSubTest(t, "keys", mc, subTestKeys) 44 | runSubTest(t, "json", mc, subTestJSON) 45 | runSubTest(t, "indexes", mc, subTestIndexes) 46 | runSubTest(t, "transactions", mc, subTestTransactions) 47 | runSubTest(t, "scripts", mc, subTestScripts) 48 | runSubTest(t, "raft", mc, subTestRaft) 49 | } 50 | 51 | func runSubTest(t *testing.T, name string, mc *mockCluster, test func(t *testing.T, mc *mockCluster)) { 52 | t.Run(name, func(t *testing.T) { 53 | fmt.Printf(bright+"Testing %s\n"+clear, name) 54 | test(t, mc) 55 | }) 56 | } 57 | 58 | func runStep(t *testing.T, mc *mockCluster, name string, step func(mc *mockCluster) error) { 59 | if err := func() error { 60 | // reset the current server 61 | mc.ResetConn() 62 | defer mc.ResetConn() 63 | // clear the database so the test is consistent 64 | if err := mc.DoBatch([][]interface{}{{"FLUSHDB"}, {"OK"}}); err != nil { 65 | return err 66 | } 67 | if err := step(mc); err != nil { 68 | return err 69 | } 70 | return nil 71 | }(); err != nil { 72 | fmt.Printf("["+red+"fail"+clear+"]: %s\n", name) 73 | t.Fatal(err) 74 | } 75 | fmt.Printf("["+green+"ok"+clear+"]: %s\n", name) 76 | } 77 | -------------------------------------------------------------------------------- /machine/json_test.go: -------------------------------------------------------------------------------- 1 | package machine 2 | 3 | import "testing" 4 | 5 | func subTestJSON(t *testing.T, mc *mockCluster) { 6 | runStep(t, mc, "JSET", json_JSET_test) 7 | runStep(t, mc, "JGET", json_JGET_test) 8 | runStep(t, mc, "JDEL", json_JDEL_test) 9 | } 10 | 11 | func json_JSET_test(mc *mockCluster) error { 12 | return mc.DoBatch([][]interface{}{ 13 | {"JSET", "user:101", "name", "Tom"}, {"OK"}, 14 | {"JSET", "user:101", "age", 46}, {"OK"}, 15 | {"GET", "user:101"}, {`{"age":46,"name":"Tom"}`}, 16 | }) 17 | } 18 | func json_JGET_test(mc *mockCluster) error { 19 | return mc.DoBatch([][]interface{}{ 20 | {"JSET", "user:101", "name", "Tom"}, {"OK"}, 21 | {"JSET", "user:101", "age", 46}, {"OK"}, 22 | {"GET", "user:101"}, {`{"age":46,"name":"Tom"}`}, 23 | {"JGET", "user:101", "age"}, {"46"}, 24 | {"JSET", "user:101", "a.b.c", "hello"}, {"OK"}, 25 | {"GET", "user:101"}, {`{"a":{"b":{"c":"hello"}},"age":46,"name":"Tom"}`}, 26 | }) 27 | } 28 | func json_JDEL_test(mc *mockCluster) error { 29 | return mc.DoBatch([][]interface{}{ 30 | {"JSET", "user:101", "name", "Tom"}, {"OK"}, 31 | {"JSET", "user:101", "age", 46}, {"OK"}, 32 | {"GET", "user:101"}, {`{"age":46,"name":"Tom"}`}, 33 | {"JGET", "user:101", "age"}, {"46"}, 34 | {"JSET", "user:101", "a.b.c", "hello"}, {"OK"}, 35 | {"GET", "user:101"}, {`{"a":{"b":{"c":"hello"}},"age":46,"name":"Tom"}`}, 36 | {"JDEL", "user:101", "a.b"}, {1}, 37 | {"GET", "user:101"}, {`{"a":{},"age":46,"name":"Tom"}`}, 38 | }) 39 | } 40 | -------------------------------------------------------------------------------- /machine/scripts_test.go: -------------------------------------------------------------------------------- 1 | package machine 2 | 3 | import ( 4 | "crypto/sha1" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func subTestScripts(t *testing.T, mc *mockCluster) { 10 | runStep(t, mc, "basic", scripts_SIMPLE_test) 11 | runStep(t, mc, "set data", scripts_SET_test) 12 | runStep(t, mc, "readonly", scripts_READONLY_test) 13 | runStep(t, mc, "sha", scripts_EVALSHA_test) 14 | } 15 | func scripts_SIMPLE_test(mc *mockCluster) error { 16 | return mc.DoBatch([][]interface{}{ 17 | {"EVAL", `return 1`, 0}, {1}, 18 | {"EVAL", `return KEYS[0]+KEYS[1]+ARGV[0]+ARGV[1]`, 2, "k1", "k2", "a1", "a2"}, {"k1k2a1a2"}, 19 | }) 20 | } 21 | func scripts_SET_test(mc *mockCluster) error { 22 | return mc.DoBatch([][]interface{}{ 23 | {"EVAL", `sdb.call("set", "1", "2");return sdb.call("get", "1")`, 0}, {"2"}, 24 | {"GET", "1"}, {"2"}, 25 | }) 26 | } 27 | func scripts_READONLY_test(mc *mockCluster) error { 28 | return mc.DoBatch([][]interface{}{ 29 | {"EVALRO", `sdb.call("set", "1", "2");return sdb.call("get", "1")`, 0}, {"tx not writable"}, 30 | {"SET", "1", "2"}, {"OK"}, 31 | {"EVALRO", `return sdb.call("get", "1")`, 0}, {"2"}, 32 | }) 33 | } 34 | func scripts_EVALSHA_test(mc *mockCluster) error { 35 | scriptSet := `return sdb.call("set", "1", ARGV[0])` 36 | scriptGet := `return sdb.call("get", "1")` 37 | shaSet := fmt.Sprintf("%x", sha1.Sum([]byte(scriptSet))) 38 | shaGet := fmt.Sprintf("%x", sha1.Sum([]byte(scriptGet))) 39 | return mc.DoBatch([][]interface{}{ 40 | {"EVALSHA", `asdf`, 0}, {"NOSCRIPT No matching script. Please use EVAL."}, 41 | {"SCRIPT", "LOAD", scriptSet}, {shaSet}, 42 | {"SCRIPT", "LOAD", scriptGet}, {shaGet}, 43 | {"EVALSHA", shaSet, 0, "value"}, {"OK"}, 44 | {"EVALSHARO", shaGet, 0}, {"value"}, 45 | {"FLUSHDB"}, {"OK"}, 46 | {"EVALSHARO", shaGet, 0}, {nil}, 47 | {"SCRIPT", "LOAD", scriptSet}, {shaSet}, 48 | {"SCRIPT", "LOAD", scriptGet}, {shaGet}, 49 | {"EVALSHA", shaSet, 0, "value"}, {"OK"}, 50 | {"EVALSHARO", shaGet, 0}, {"value"}, 51 | {"SCRIPT", "FLUSH"}, {"OK"}, 52 | {"EVALSHARO", shaGet, 0}, {"NOSCRIPT No matching script. Please use EVAL."}, 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /machine/snapshot.go: -------------------------------------------------------------------------------- 1 | package machine 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io" 7 | "os" 8 | "strings" 9 | 10 | "github.com/tidwall/buntdb" 11 | ) 12 | 13 | // Restore restores a snapshot 14 | func (m *Machine) Restore(rd io.Reader) error { 15 | m.mu.Lock() 16 | defer m.mu.Unlock() 17 | 18 | // read the snapshot into a new machine. 19 | // the new machine will have the entire keyspace, but will be missing 20 | // indexes and scripts. 21 | nm := &Machine{} 22 | if err := nm.reopenBlankDB(rd, func(keys []string) { m.onExpired(keys) }); err != nil { 23 | return err 24 | } 25 | 26 | // rebuild the indexes 27 | if err := nm.db.Update(func(tx *buntdb.Tx) error { 28 | var metas []string 29 | if err := tx.AscendGreaterOrEqual("", indexKeyPrefix, func(key, val string) bool { 30 | if !strings.HasPrefix(key, indexKeyPrefix) { 31 | return false 32 | } 33 | metas = append(metas, key, val) 34 | return true 35 | }); err != nil { 36 | return err 37 | } 38 | for i := 0; i < len(metas); i += 2 { 39 | name := metas[i] 40 | var rargs indexArgs 41 | if err := json.Unmarshal([]byte(metas[i+1]), &rargs); err != nil { 42 | return fmt.Errorf("parsing index '%v': %v", name, err) 43 | } 44 | if err := dbSetIndex(tx, rargs); err != nil { 45 | return err 46 | } 47 | } 48 | return nil 49 | }); err != nil { 50 | return err 51 | } 52 | 53 | // close and delete the previous file 54 | m.db.Close() 55 | os.RemoveAll(m.file) 56 | 57 | // set the important fields to the new machine, file, and script machine. 58 | m.db = nm.db 59 | m.file = nm.file 60 | 61 | return nil 62 | } 63 | 64 | // Snapshot creates a snapshot 65 | func (m *Machine) Snapshot(wr io.Writer) error { 66 | var pos int64 67 | var file string 68 | err := func() error { 69 | m.mu.RLock() 70 | defer m.mu.RUnlock() 71 | f, err := os.Open(m.file) 72 | if err != nil { 73 | return err 74 | } 75 | defer f.Close() 76 | pos, err = f.Seek(0, 2) 77 | if err != nil { 78 | return err 79 | } 80 | file = m.file 81 | return nil 82 | }() 83 | if err != nil { 84 | return err 85 | } 86 | // write the file data 87 | f, err := os.Open(file) 88 | if err != nil { 89 | return err 90 | } 91 | defer f.Close() 92 | if _, err := io.CopyN(wr, f, pos); err != nil { 93 | return err 94 | } 95 | return nil 96 | } 97 | -------------------------------------------------------------------------------- /resources/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | VERSION="0.4.0" 5 | PROTECTED_MODE="no" 6 | 7 | export GO15VENDOREXPERIMENT=1 8 | 9 | cd $(dirname "${BASH_SOURCE[0]}")/../ 10 | OD="$(pwd)" 11 | 12 | # temp directory for storing isolated environment. 13 | TMP="$(mktemp -d -t sdb.XXXX)" 14 | function rmtemp { 15 | rm -rf "$TMP" 16 | } 17 | trap rmtemp EXIT 18 | 19 | if [ "$NOCOPY" != "1" ]; then 20 | # copy all files to an isloated directory. 21 | WD="$TMP/src/github.com/tidwall/summitdb" 22 | export GOPATH="$TMP" 23 | for file in `find . -type f`; do 24 | # TODO: use .gitignore to ignore, or possibly just use git to determine the file list. 25 | if [[ "$file" != "." && "$file" != ./.git* && "$file" != ./data* && "$file" != ./summitdb-* ]]; then 26 | mkdir -p "$WD/$(dirname "${file}")" 27 | cp -P "$file" "$WD/$(dirname "${file}")" 28 | fi 29 | done 30 | cd $WD 31 | fi 32 | 33 | package(){ 34 | echo Packaging $1 Binary 35 | bdir=summitdb-${VERSION}-$2-$3 36 | rm -rf packages/$bdir && mkdir -p packages/$bdir 37 | GOOS=$2 GOARCH=$3 ${BASH_SOURCE[0]} # ./build.sh 38 | if [ "$2" == "windows" ]; then 39 | mv summitdb-server packages/$bdir/summitdb-server.exe 40 | else 41 | mv summitdb-server packages/$bdir 42 | fi 43 | cp README.md LICENSE CHANGELOG.md packages/$bdir 44 | cd packages 45 | if [ "$2" == "linux" ]; then 46 | tar -zcf $bdir.tar.gz $bdir 47 | else 48 | zip -r -q $bdir.zip $bdir 49 | fi 50 | rm -rf $bdir 51 | cd .. 52 | } 53 | 54 | if [ "$1" == "package" ]; then 55 | rm -rf packages/ 56 | package "Windows" "windows" "amd64" 57 | package "Mac" "darwin" "amd64" 58 | package "Linux" "linux" "amd64" 59 | package "ARM" "linux" "arm" 60 | package "FreeBSD" "freebsd" "amd64" 61 | exit 62 | fi 63 | 64 | # build and store objects into original directory. 65 | go build -ldflags "-X main.version=$VERSION" -o "$OD/summitdb-server" cmd/summitdb-server/*.go 66 | 67 | -------------------------------------------------------------------------------- /resources/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidwall/summitdb/bc639291bb251f21b05c7e87526faa28f5f8ae23/resources/logo.png -------------------------------------------------------------------------------- /resources/vendor.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | cd $(dirname "${BASH_SOURCE[0]}")/.. 6 | 7 | if [ "$1" == "" ]; then 8 | echo missing argument 9 | else 10 | mkdir -p vendor/$1 11 | cp -rf ${GOPATH}/src/$1/ vendor/$1/ 12 | if [ -d vendor/$1/.git ]; then 13 | wd=`pwd` 14 | cd vendor/$1 15 | git clean -fd 16 | cd "$wd" 17 | fi 18 | rm -rf vendor/$1/.git \ 19 | vendor/$1/.bzr \ 20 | vendor/$1/.hg \ 21 | vendor/$1/.svn 22 | fi 23 | -------------------------------------------------------------------------------- /vendor/github.com/armon/go-metrics/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | 24 | /metrics.out 25 | -------------------------------------------------------------------------------- /vendor/github.com/armon/go-metrics/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Armon Dadgar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/armon/go-metrics/const_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package metrics 4 | 5 | import ( 6 | "syscall" 7 | ) 8 | 9 | const ( 10 | // DefaultSignal is used with DefaultInmemSignal 11 | DefaultSignal = syscall.SIGUSR1 12 | ) 13 | -------------------------------------------------------------------------------- /vendor/github.com/armon/go-metrics/const_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package metrics 4 | 5 | import ( 6 | "syscall" 7 | ) 8 | 9 | const ( 10 | // DefaultSignal is used with DefaultInmemSignal 11 | // Windows has no SIGUSR1, use SIGBREAK 12 | DefaultSignal = syscall.Signal(21) 13 | ) 14 | -------------------------------------------------------------------------------- /vendor/github.com/armon/go-metrics/inmem_signal_test.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "bytes" 5 | "os" 6 | "strings" 7 | "syscall" 8 | "testing" 9 | "time" 10 | ) 11 | 12 | func TestInmemSignal(t *testing.T) { 13 | buf := bytes.NewBuffer(nil) 14 | inm := NewInmemSink(10*time.Millisecond, 50*time.Millisecond) 15 | sig := NewInmemSignal(inm, syscall.SIGUSR1, buf) 16 | defer sig.Stop() 17 | 18 | inm.SetGauge([]string{"foo"}, 42) 19 | inm.EmitKey([]string{"bar"}, 42) 20 | inm.IncrCounter([]string{"baz"}, 42) 21 | inm.AddSample([]string{"wow"}, 42) 22 | 23 | // Wait for period to end 24 | time.Sleep(15 * time.Millisecond) 25 | 26 | // Send signal! 27 | syscall.Kill(os.Getpid(), syscall.SIGUSR1) 28 | 29 | // Wait for flush 30 | time.Sleep(10 * time.Millisecond) 31 | 32 | // Check the output 33 | out := string(buf.Bytes()) 34 | if !strings.Contains(out, "[G] 'foo': 42") { 35 | t.Fatalf("bad: %v", out) 36 | } 37 | if !strings.Contains(out, "[P] 'bar': 42") { 38 | t.Fatalf("bad: %v", out) 39 | } 40 | if !strings.Contains(out, "[C] 'baz': Count: 1 Sum: 42") { 41 | t.Fatalf("bad: %v", out) 42 | } 43 | if !strings.Contains(out, "[S] 'wow': Count: 1 Sum: 42") { 44 | t.Fatalf("bad: %v", out) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/armon/go-metrics/inmem_test.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "math" 5 | "testing" 6 | "time" 7 | ) 8 | 9 | func TestInmemSink(t *testing.T) { 10 | inm := NewInmemSink(10*time.Millisecond, 50*time.Millisecond) 11 | 12 | data := inm.Data() 13 | if len(data) != 1 { 14 | t.Fatalf("bad: %v", data) 15 | } 16 | 17 | // Add data points 18 | inm.SetGauge([]string{"foo", "bar"}, 42) 19 | inm.EmitKey([]string{"foo", "bar"}, 42) 20 | inm.IncrCounter([]string{"foo", "bar"}, 20) 21 | inm.IncrCounter([]string{"foo", "bar"}, 22) 22 | inm.AddSample([]string{"foo", "bar"}, 20) 23 | inm.AddSample([]string{"foo", "bar"}, 22) 24 | 25 | data = inm.Data() 26 | if len(data) != 1 { 27 | t.Fatalf("bad: %v", data) 28 | } 29 | 30 | intvM := data[0] 31 | intvM.RLock() 32 | 33 | if time.Now().Sub(intvM.Interval) > 10*time.Millisecond { 34 | t.Fatalf("interval too old") 35 | } 36 | if intvM.Gauges["foo.bar"] != 42 { 37 | t.Fatalf("bad val: %v", intvM.Gauges) 38 | } 39 | if intvM.Points["foo.bar"][0] != 42 { 40 | t.Fatalf("bad val: %v", intvM.Points) 41 | } 42 | 43 | agg := intvM.Counters["foo.bar"] 44 | if agg.Count != 2 { 45 | t.Fatalf("bad val: %v", agg) 46 | } 47 | if agg.Rate != 200 { 48 | t.Fatalf("bad val: %v", agg.Rate) 49 | } 50 | if agg.Sum != 42 { 51 | t.Fatalf("bad val: %v", agg) 52 | } 53 | if agg.SumSq != 884 { 54 | t.Fatalf("bad val: %v", agg) 55 | } 56 | if agg.Min != 20 { 57 | t.Fatalf("bad val: %v", agg) 58 | } 59 | if agg.Max != 22 { 60 | t.Fatalf("bad val: %v", agg) 61 | } 62 | if agg.Mean() != 21 { 63 | t.Fatalf("bad val: %v", agg) 64 | } 65 | if agg.Stddev() != math.Sqrt(2) { 66 | t.Fatalf("bad val: %v", agg) 67 | } 68 | 69 | if agg.LastUpdated.IsZero() { 70 | t.Fatalf("agg.LastUpdated is not set: %v", agg) 71 | } 72 | 73 | diff := time.Now().Sub(agg.LastUpdated).Seconds() 74 | if diff > 1 { 75 | t.Fatalf("time diff too great: %f", diff) 76 | } 77 | 78 | if agg = intvM.Samples["foo.bar"]; agg == nil { 79 | t.Fatalf("missing sample") 80 | } 81 | 82 | intvM.RUnlock() 83 | 84 | for i := 1; i < 10; i++ { 85 | time.Sleep(10 * time.Millisecond) 86 | inm.SetGauge([]string{"foo", "bar"}, 42) 87 | data = inm.Data() 88 | if len(data) != min(i+1, 5) { 89 | t.Fatalf("bad: %v", data) 90 | } 91 | } 92 | 93 | // Should not exceed 5 intervals! 94 | time.Sleep(10 * time.Millisecond) 95 | inm.SetGauge([]string{"foo", "bar"}, 42) 96 | data = inm.Data() 97 | if len(data) != 5 { 98 | t.Fatalf("bad: %v", data) 99 | } 100 | } 101 | 102 | func min(a, b int) int { 103 | if a < b { 104 | return a 105 | } 106 | return b 107 | } 108 | -------------------------------------------------------------------------------- /vendor/github.com/armon/go-metrics/prometheus/prometheus.go: -------------------------------------------------------------------------------- 1 | // +build go1.3 2 | package prometheus 3 | 4 | import ( 5 | "strings" 6 | "sync" 7 | "time" 8 | 9 | "github.com/prometheus/client_golang/prometheus" 10 | ) 11 | 12 | type PrometheusSink struct { 13 | mu sync.Mutex 14 | gauges map[string]prometheus.Gauge 15 | summaries map[string]prometheus.Summary 16 | counters map[string]prometheus.Counter 17 | } 18 | 19 | func NewPrometheusSink() (*PrometheusSink, error) { 20 | return &PrometheusSink{ 21 | gauges: make(map[string]prometheus.Gauge), 22 | summaries: make(map[string]prometheus.Summary), 23 | counters: make(map[string]prometheus.Counter), 24 | }, nil 25 | } 26 | 27 | func (p *PrometheusSink) flattenKey(parts []string) string { 28 | joined := strings.Join(parts, "_") 29 | joined = strings.Replace(joined, " ", "_", -1) 30 | joined = strings.Replace(joined, ".", "_", -1) 31 | joined = strings.Replace(joined, "-", "_", -1) 32 | joined = strings.Replace(joined, "=", "_", -1) 33 | return joined 34 | } 35 | 36 | func (p *PrometheusSink) SetGauge(parts []string, val float32) { 37 | p.mu.Lock() 38 | defer p.mu.Unlock() 39 | key := p.flattenKey(parts) 40 | g, ok := p.gauges[key] 41 | if !ok { 42 | g = prometheus.NewGauge(prometheus.GaugeOpts{ 43 | Name: key, 44 | Help: key, 45 | }) 46 | prometheus.MustRegister(g) 47 | p.gauges[key] = g 48 | } 49 | g.Set(float64(val)) 50 | } 51 | 52 | func (p *PrometheusSink) AddSample(parts []string, val float32) { 53 | p.mu.Lock() 54 | defer p.mu.Unlock() 55 | key := p.flattenKey(parts) 56 | g, ok := p.summaries[key] 57 | if !ok { 58 | g = prometheus.NewSummary(prometheus.SummaryOpts{ 59 | Name: key, 60 | Help: key, 61 | MaxAge: 10 * time.Second, 62 | }) 63 | prometheus.MustRegister(g) 64 | p.summaries[key] = g 65 | } 66 | g.Observe(float64(val)) 67 | } 68 | 69 | // EmitKey is not implemented. Prometheus doesn’t offer a type for which an 70 | // arbitrary number of values is retained, as Prometheus works with a pull 71 | // model, rather than a push model. 72 | func (p *PrometheusSink) EmitKey(key []string, val float32) { 73 | } 74 | 75 | func (p *PrometheusSink) IncrCounter(parts []string, val float32) { 76 | p.mu.Lock() 77 | defer p.mu.Unlock() 78 | key := p.flattenKey(parts) 79 | g, ok := p.counters[key] 80 | if !ok { 81 | g = prometheus.NewCounter(prometheus.CounterOpts{ 82 | Name: key, 83 | Help: key, 84 | }) 85 | prometheus.MustRegister(g) 86 | p.counters[key] = g 87 | } 88 | g.Add(float64(val)) 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/armon/go-metrics/sink.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | // The MetricSink interface is used to transmit metrics information 4 | // to an external system 5 | type MetricSink interface { 6 | // A Gauge should retain the last value it is set to 7 | SetGauge(key []string, val float32) 8 | 9 | // Should emit a Key/Value pair for each call 10 | EmitKey(key []string, val float32) 11 | 12 | // Counters should accumulate values 13 | IncrCounter(key []string, val float32) 14 | 15 | // Samples are for timing information, where quantiles are used 16 | AddSample(key []string, val float32) 17 | } 18 | 19 | // BlackholeSink is used to just blackhole messages 20 | type BlackholeSink struct{} 21 | 22 | func (*BlackholeSink) SetGauge(key []string, val float32) {} 23 | func (*BlackholeSink) EmitKey(key []string, val float32) {} 24 | func (*BlackholeSink) IncrCounter(key []string, val float32) {} 25 | func (*BlackholeSink) AddSample(key []string, val float32) {} 26 | 27 | // FanoutSink is used to sink to fanout values to multiple sinks 28 | type FanoutSink []MetricSink 29 | 30 | func (fh FanoutSink) SetGauge(key []string, val float32) { 31 | for _, s := range fh { 32 | s.SetGauge(key, val) 33 | } 34 | } 35 | 36 | func (fh FanoutSink) EmitKey(key []string, val float32) { 37 | for _, s := range fh { 38 | s.EmitKey(key, val) 39 | } 40 | } 41 | 42 | func (fh FanoutSink) IncrCounter(key []string, val float32) { 43 | for _, s := range fh { 44 | s.IncrCounter(key, val) 45 | } 46 | } 47 | 48 | func (fh FanoutSink) AddSample(key []string, val float32) { 49 | for _, s := range fh { 50 | s.AddSample(key, val) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/armon/go-metrics/statsd_test.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "bufio" 5 | "bytes" 6 | "net" 7 | "testing" 8 | "time" 9 | ) 10 | 11 | func TestStatsd_Flatten(t *testing.T) { 12 | s := &StatsdSink{} 13 | flat := s.flattenKey([]string{"a", "b", "c", "d"}) 14 | if flat != "a.b.c.d" { 15 | t.Fatalf("Bad flat") 16 | } 17 | } 18 | 19 | func TestStatsd_PushFullQueue(t *testing.T) { 20 | q := make(chan string, 1) 21 | q <- "full" 22 | 23 | s := &StatsdSink{metricQueue: q} 24 | s.pushMetric("omit") 25 | 26 | out := <-q 27 | if out != "full" { 28 | t.Fatalf("bad val %v", out) 29 | } 30 | 31 | select { 32 | case v := <-q: 33 | t.Fatalf("bad val %v", v) 34 | default: 35 | } 36 | } 37 | 38 | func TestStatsd_Conn(t *testing.T) { 39 | addr := "127.0.0.1:7524" 40 | done := make(chan bool) 41 | go func() { 42 | list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 7524}) 43 | if err != nil { 44 | panic(err) 45 | } 46 | defer list.Close() 47 | buf := make([]byte, 1500) 48 | n, err := list.Read(buf) 49 | if err != nil { 50 | panic(err) 51 | } 52 | buf = buf[:n] 53 | reader := bufio.NewReader(bytes.NewReader(buf)) 54 | 55 | line, err := reader.ReadString('\n') 56 | if err != nil { 57 | t.Fatalf("unexpected err %s", err) 58 | } 59 | if line != "gauge.val:1.000000|g\n" { 60 | t.Fatalf("bad line %s", line) 61 | } 62 | 63 | line, err = reader.ReadString('\n') 64 | if err != nil { 65 | t.Fatalf("unexpected err %s", err) 66 | } 67 | if line != "key.other:2.000000|kv\n" { 68 | t.Fatalf("bad line %s", line) 69 | } 70 | 71 | line, err = reader.ReadString('\n') 72 | if err != nil { 73 | t.Fatalf("unexpected err %s", err) 74 | } 75 | if line != "counter.me:3.000000|c\n" { 76 | t.Fatalf("bad line %s", line) 77 | } 78 | 79 | line, err = reader.ReadString('\n') 80 | if err != nil { 81 | t.Fatalf("unexpected err %s", err) 82 | } 83 | if line != "sample.slow_thingy:4.000000|ms\n" { 84 | t.Fatalf("bad line %s", line) 85 | } 86 | 87 | done <- true 88 | }() 89 | s, err := NewStatsdSink(addr) 90 | if err != nil { 91 | t.Fatalf("bad error") 92 | } 93 | 94 | s.SetGauge([]string{"gauge", "val"}, float32(1)) 95 | s.EmitKey([]string{"key", "other"}, float32(2)) 96 | s.IncrCounter([]string{"counter", "me"}, float32(3)) 97 | s.AddSample([]string{"sample", "slow thingy"}, float32(4)) 98 | 99 | select { 100 | case <-done: 101 | s.Shutdown() 102 | case <-time.After(3 * time.Second): 103 | t.Fatalf("timeout") 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/armon/go-metrics/statsite_test.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "bufio" 5 | "net" 6 | "testing" 7 | "time" 8 | ) 9 | 10 | func acceptConn(addr string) net.Conn { 11 | ln, _ := net.Listen("tcp", addr) 12 | conn, _ := ln.Accept() 13 | return conn 14 | } 15 | 16 | func TestStatsite_Flatten(t *testing.T) { 17 | s := &StatsiteSink{} 18 | flat := s.flattenKey([]string{"a", "b", "c", "d"}) 19 | if flat != "a.b.c.d" { 20 | t.Fatalf("Bad flat") 21 | } 22 | } 23 | 24 | func TestStatsite_PushFullQueue(t *testing.T) { 25 | q := make(chan string, 1) 26 | q <- "full" 27 | 28 | s := &StatsiteSink{metricQueue: q} 29 | s.pushMetric("omit") 30 | 31 | out := <-q 32 | if out != "full" { 33 | t.Fatalf("bad val %v", out) 34 | } 35 | 36 | select { 37 | case v := <-q: 38 | t.Fatalf("bad val %v", v) 39 | default: 40 | } 41 | } 42 | 43 | func TestStatsite_Conn(t *testing.T) { 44 | addr := "localhost:7523" 45 | done := make(chan bool) 46 | go func() { 47 | conn := acceptConn(addr) 48 | reader := bufio.NewReader(conn) 49 | 50 | line, err := reader.ReadString('\n') 51 | if err != nil { 52 | t.Fatalf("unexpected err %s", err) 53 | } 54 | if line != "gauge.val:1.000000|g\n" { 55 | t.Fatalf("bad line %s", line) 56 | } 57 | 58 | line, err = reader.ReadString('\n') 59 | if err != nil { 60 | t.Fatalf("unexpected err %s", err) 61 | } 62 | if line != "key.other:2.000000|kv\n" { 63 | t.Fatalf("bad line %s", line) 64 | } 65 | 66 | line, err = reader.ReadString('\n') 67 | if err != nil { 68 | t.Fatalf("unexpected err %s", err) 69 | } 70 | if line != "counter.me:3.000000|c\n" { 71 | t.Fatalf("bad line %s", line) 72 | } 73 | 74 | line, err = reader.ReadString('\n') 75 | if err != nil { 76 | t.Fatalf("unexpected err %s", err) 77 | } 78 | if line != "sample.slow_thingy:4.000000|ms\n" { 79 | t.Fatalf("bad line %s", line) 80 | } 81 | 82 | conn.Close() 83 | done <- true 84 | }() 85 | s, err := NewStatsiteSink(addr) 86 | if err != nil { 87 | t.Fatalf("bad error") 88 | } 89 | 90 | s.SetGauge([]string{"gauge", "val"}, float32(1)) 91 | s.EmitKey([]string{"key", "other"}, float32(2)) 92 | s.IncrCounter([]string{"counter", "me"}, float32(3)) 93 | s.AddSample([]string{"sample", "slow thingy"}, float32(4)) 94 | 95 | select { 96 | case <-done: 97 | s.Shutdown() 98 | case <-time.After(3 * time.Second): 99 | t.Fatalf("timeout") 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/.gitignore: -------------------------------------------------------------------------------- 1 | *.prof 2 | *.test 3 | *.swp 4 | /bin/ 5 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Ben Johnson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/Makefile: -------------------------------------------------------------------------------- 1 | BRANCH=`git rev-parse --abbrev-ref HEAD` 2 | COMMIT=`git rev-parse --short HEAD` 3 | GOLDFLAGS="-X main.branch $(BRANCH) -X main.commit $(COMMIT)" 4 | 5 | default: build 6 | 7 | race: 8 | @go test -v -race -test.run="TestSimulate_(100op|1000op)" 9 | 10 | # go get github.com/kisielk/errcheck 11 | errcheck: 12 | @errcheck -ignorepkg=bytes -ignore=os:Remove github.com/boltdb/bolt 13 | 14 | test: 15 | @go test -v -cover . 16 | @go test -v ./cmd/bolt 17 | 18 | .PHONY: fmt test 19 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: "{build}" 2 | 3 | os: Windows Server 2012 R2 4 | 5 | clone_folder: c:\gopath\src\github.com\boltdb\bolt 6 | 7 | environment: 8 | GOPATH: c:\gopath 9 | 10 | install: 11 | - echo %PATH% 12 | - echo %GOPATH% 13 | - go version 14 | - go env 15 | - go get -v -t ./... 16 | 17 | build_script: 18 | - go test -v ./... 19 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/bolt_386.go: -------------------------------------------------------------------------------- 1 | package bolt 2 | 3 | // maxMapSize represents the largest mmap size supported by Bolt. 4 | const maxMapSize = 0x7FFFFFFF // 2GB 5 | 6 | // maxAllocSize is the size used when creating array pointers. 7 | const maxAllocSize = 0xFFFFFFF 8 | 9 | // Are unaligned load/stores broken on this arch? 10 | var brokenUnaligned = false 11 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/bolt_amd64.go: -------------------------------------------------------------------------------- 1 | package bolt 2 | 3 | // maxMapSize represents the largest mmap size supported by Bolt. 4 | const maxMapSize = 0xFFFFFFFFFFFF // 256TB 5 | 6 | // maxAllocSize is the size used when creating array pointers. 7 | const maxAllocSize = 0x7FFFFFFF 8 | 9 | // Are unaligned load/stores broken on this arch? 10 | var brokenUnaligned = false 11 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/bolt_arm.go: -------------------------------------------------------------------------------- 1 | package bolt 2 | 3 | import "unsafe" 4 | 5 | // maxMapSize represents the largest mmap size supported by Bolt. 6 | const maxMapSize = 0x7FFFFFFF // 2GB 7 | 8 | // maxAllocSize is the size used when creating array pointers. 9 | const maxAllocSize = 0xFFFFFFF 10 | 11 | // Are unaligned load/stores broken on this arch? 12 | var brokenUnaligned bool 13 | 14 | func init() { 15 | // Simple check to see whether this arch handles unaligned load/stores 16 | // correctly. 17 | 18 | // ARM9 and older devices require load/stores to be from/to aligned 19 | // addresses. If not, the lower 2 bits are cleared and that address is 20 | // read in a jumbled up order. 21 | 22 | // See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka15414.html 23 | 24 | raw := [6]byte{0xfe, 0xef, 0x11, 0x22, 0x22, 0x11} 25 | val := *(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(&raw)) + 2)) 26 | 27 | brokenUnaligned = val != 0x11222211 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/bolt_arm64.go: -------------------------------------------------------------------------------- 1 | // +build arm64 2 | 3 | package bolt 4 | 5 | // maxMapSize represents the largest mmap size supported by Bolt. 6 | const maxMapSize = 0xFFFFFFFFFFFF // 256TB 7 | 8 | // maxAllocSize is the size used when creating array pointers. 9 | const maxAllocSize = 0x7FFFFFFF 10 | 11 | // Are unaligned load/stores broken on this arch? 12 | var brokenUnaligned = false 13 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/bolt_linux.go: -------------------------------------------------------------------------------- 1 | package bolt 2 | 3 | import ( 4 | "syscall" 5 | ) 6 | 7 | // fdatasync flushes written data to a file descriptor. 8 | func fdatasync(db *DB) error { 9 | return syscall.Fdatasync(int(db.file.Fd())) 10 | } 11 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/bolt_openbsd.go: -------------------------------------------------------------------------------- 1 | package bolt 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | const ( 9 | msAsync = 1 << iota // perform asynchronous writes 10 | msSync // perform synchronous writes 11 | msInvalidate // invalidate cached data 12 | ) 13 | 14 | func msync(db *DB) error { 15 | _, _, errno := syscall.Syscall(syscall.SYS_MSYNC, uintptr(unsafe.Pointer(db.data)), uintptr(db.datasz), msInvalidate) 16 | if errno != 0 { 17 | return errno 18 | } 19 | return nil 20 | } 21 | 22 | func fdatasync(db *DB) error { 23 | if db.data != nil { 24 | return msync(db) 25 | } 26 | return db.file.Sync() 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/bolt_ppc.go: -------------------------------------------------------------------------------- 1 | // +build ppc 2 | 3 | package bolt 4 | 5 | // maxMapSize represents the largest mmap size supported by Bolt. 6 | const maxMapSize = 0x7FFFFFFF // 2GB 7 | 8 | // maxAllocSize is the size used when creating array pointers. 9 | const maxAllocSize = 0xFFFFFFF 10 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/bolt_ppc64.go: -------------------------------------------------------------------------------- 1 | // +build ppc64 2 | 3 | package bolt 4 | 5 | // maxMapSize represents the largest mmap size supported by Bolt. 6 | const maxMapSize = 0xFFFFFFFFFFFF // 256TB 7 | 8 | // maxAllocSize is the size used when creating array pointers. 9 | const maxAllocSize = 0x7FFFFFFF 10 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/bolt_ppc64le.go: -------------------------------------------------------------------------------- 1 | // +build ppc64le 2 | 3 | package bolt 4 | 5 | // maxMapSize represents the largest mmap size supported by Bolt. 6 | const maxMapSize = 0xFFFFFFFFFFFF // 256TB 7 | 8 | // maxAllocSize is the size used when creating array pointers. 9 | const maxAllocSize = 0x7FFFFFFF 10 | 11 | // Are unaligned load/stores broken on this arch? 12 | var brokenUnaligned = false 13 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/bolt_s390x.go: -------------------------------------------------------------------------------- 1 | // +build s390x 2 | 3 | package bolt 4 | 5 | // maxMapSize represents the largest mmap size supported by Bolt. 6 | const maxMapSize = 0xFFFFFFFFFFFF // 256TB 7 | 8 | // maxAllocSize is the size used when creating array pointers. 9 | const maxAllocSize = 0x7FFFFFFF 10 | 11 | // Are unaligned load/stores broken on this arch? 12 | var brokenUnaligned = false 13 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/bolt_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows,!plan9,!solaris 2 | 3 | package bolt 4 | 5 | import ( 6 | "fmt" 7 | "os" 8 | "syscall" 9 | "time" 10 | "unsafe" 11 | ) 12 | 13 | // flock acquires an advisory lock on a file descriptor. 14 | func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) error { 15 | var t time.Time 16 | for { 17 | // If we're beyond our timeout then return an error. 18 | // This can only occur after we've attempted a flock once. 19 | if t.IsZero() { 20 | t = time.Now() 21 | } else if timeout > 0 && time.Since(t) > timeout { 22 | return ErrTimeout 23 | } 24 | flag := syscall.LOCK_SH 25 | if exclusive { 26 | flag = syscall.LOCK_EX 27 | } 28 | 29 | // Otherwise attempt to obtain an exclusive lock. 30 | err := syscall.Flock(int(db.file.Fd()), flag|syscall.LOCK_NB) 31 | if err == nil { 32 | return nil 33 | } else if err != syscall.EWOULDBLOCK { 34 | return err 35 | } 36 | 37 | // Wait for a bit and try again. 38 | time.Sleep(50 * time.Millisecond) 39 | } 40 | } 41 | 42 | // funlock releases an advisory lock on a file descriptor. 43 | func funlock(db *DB) error { 44 | return syscall.Flock(int(db.file.Fd()), syscall.LOCK_UN) 45 | } 46 | 47 | // mmap memory maps a DB's data file. 48 | func mmap(db *DB, sz int) error { 49 | // Map the data file to memory. 50 | b, err := syscall.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED|db.MmapFlags) 51 | if err != nil { 52 | return err 53 | } 54 | 55 | // Advise the kernel that the mmap is accessed randomly. 56 | if err := madvise(b, syscall.MADV_RANDOM); err != nil { 57 | return fmt.Errorf("madvise: %s", err) 58 | } 59 | 60 | // Save the original byte slice and convert to a byte array pointer. 61 | db.dataref = b 62 | db.data = (*[maxMapSize]byte)(unsafe.Pointer(&b[0])) 63 | db.datasz = sz 64 | return nil 65 | } 66 | 67 | // munmap unmaps a DB's data file from memory. 68 | func munmap(db *DB) error { 69 | // Ignore the unmap if we have no mapped data. 70 | if db.dataref == nil { 71 | return nil 72 | } 73 | 74 | // Unmap using the original byte slice. 75 | err := syscall.Munmap(db.dataref) 76 | db.dataref = nil 77 | db.data = nil 78 | db.datasz = 0 79 | return err 80 | } 81 | 82 | // NOTE: This function is copied from stdlib because it is not available on darwin. 83 | func madvise(b []byte, advice int) (err error) { 84 | _, _, e1 := syscall.Syscall(syscall.SYS_MADVISE, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), uintptr(advice)) 85 | if e1 != 0 { 86 | err = e1 87 | } 88 | return 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/bolt_unix_solaris.go: -------------------------------------------------------------------------------- 1 | package bolt 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "syscall" 7 | "time" 8 | "unsafe" 9 | 10 | "golang.org/x/sys/unix" 11 | ) 12 | 13 | // flock acquires an advisory lock on a file descriptor. 14 | func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) error { 15 | var t time.Time 16 | for { 17 | // If we're beyond our timeout then return an error. 18 | // This can only occur after we've attempted a flock once. 19 | if t.IsZero() { 20 | t = time.Now() 21 | } else if timeout > 0 && time.Since(t) > timeout { 22 | return ErrTimeout 23 | } 24 | var lock syscall.Flock_t 25 | lock.Start = 0 26 | lock.Len = 0 27 | lock.Pid = 0 28 | lock.Whence = 0 29 | lock.Pid = 0 30 | if exclusive { 31 | lock.Type = syscall.F_WRLCK 32 | } else { 33 | lock.Type = syscall.F_RDLCK 34 | } 35 | err := syscall.FcntlFlock(db.file.Fd(), syscall.F_SETLK, &lock) 36 | if err == nil { 37 | return nil 38 | } else if err != syscall.EAGAIN { 39 | return err 40 | } 41 | 42 | // Wait for a bit and try again. 43 | time.Sleep(50 * time.Millisecond) 44 | } 45 | } 46 | 47 | // funlock releases an advisory lock on a file descriptor. 48 | func funlock(db *DB) error { 49 | var lock syscall.Flock_t 50 | lock.Start = 0 51 | lock.Len = 0 52 | lock.Type = syscall.F_UNLCK 53 | lock.Whence = 0 54 | return syscall.FcntlFlock(uintptr(db.file.Fd()), syscall.F_SETLK, &lock) 55 | } 56 | 57 | // mmap memory maps a DB's data file. 58 | func mmap(db *DB, sz int) error { 59 | // Map the data file to memory. 60 | b, err := unix.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED|db.MmapFlags) 61 | if err != nil { 62 | return err 63 | } 64 | 65 | // Advise the kernel that the mmap is accessed randomly. 66 | if err := unix.Madvise(b, syscall.MADV_RANDOM); err != nil { 67 | return fmt.Errorf("madvise: %s", err) 68 | } 69 | 70 | // Save the original byte slice and convert to a byte array pointer. 71 | db.dataref = b 72 | db.data = (*[maxMapSize]byte)(unsafe.Pointer(&b[0])) 73 | db.datasz = sz 74 | return nil 75 | } 76 | 77 | // munmap unmaps a DB's data file from memory. 78 | func munmap(db *DB) error { 79 | // Ignore the unmap if we have no mapped data. 80 | if db.dataref == nil { 81 | return nil 82 | } 83 | 84 | // Unmap using the original byte slice. 85 | err := unix.Munmap(db.dataref) 86 | db.dataref = nil 87 | db.data = nil 88 | db.datasz = 0 89 | return err 90 | } 91 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/boltsync_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows,!plan9,!linux,!openbsd 2 | 3 | package bolt 4 | 5 | // fdatasync flushes written data to a file descriptor. 6 | func fdatasync(db *DB) error { 7 | return db.file.Sync() 8 | } 9 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package bolt implements a low-level key/value store in pure Go. It supports 3 | fully serializable transactions, ACID semantics, and lock-free MVCC with 4 | multiple readers and a single writer. Bolt can be used for projects that 5 | want a simple data store without the need to add large dependencies such as 6 | Postgres or MySQL. 7 | 8 | Bolt is a single-level, zero-copy, B+tree data store. This means that Bolt is 9 | optimized for fast read access and does not require recovery in the event of a 10 | system crash. Transactions which have not finished committing will simply be 11 | rolled back in the event of a crash. 12 | 13 | The design of Bolt is based on Howard Chu's LMDB database project. 14 | 15 | Bolt currently works on Windows, Mac OS X, and Linux. 16 | 17 | 18 | Basics 19 | 20 | There are only a few types in Bolt: DB, Bucket, Tx, and Cursor. The DB is 21 | a collection of buckets and is represented by a single file on disk. A bucket is 22 | a collection of unique keys that are associated with values. 23 | 24 | Transactions provide either read-only or read-write access to the database. 25 | Read-only transactions can retrieve key/value pairs and can use Cursors to 26 | iterate over the dataset sequentially. Read-write transactions can create and 27 | delete buckets and can insert and remove keys. Only one read-write transaction 28 | is allowed at a time. 29 | 30 | 31 | Caveats 32 | 33 | The database uses a read-only, memory-mapped data file to ensure that 34 | applications cannot corrupt the database, however, this means that keys and 35 | values returned from Bolt cannot be changed. Writing to a read-only byte slice 36 | will cause Go to panic. 37 | 38 | Keys and values retrieved from the database are only valid for the life of 39 | the transaction. When used outside the transaction, these byte slices can 40 | point to different data or can point to invalid memory which will cause a panic. 41 | 42 | 43 | */ 44 | package bolt 45 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/page_test.go: -------------------------------------------------------------------------------- 1 | package bolt 2 | 3 | import ( 4 | "reflect" 5 | "sort" 6 | "testing" 7 | "testing/quick" 8 | ) 9 | 10 | // Ensure that the page type can be returned in human readable format. 11 | func TestPage_typ(t *testing.T) { 12 | if typ := (&page{flags: branchPageFlag}).typ(); typ != "branch" { 13 | t.Fatalf("exp=branch; got=%v", typ) 14 | } 15 | if typ := (&page{flags: leafPageFlag}).typ(); typ != "leaf" { 16 | t.Fatalf("exp=leaf; got=%v", typ) 17 | } 18 | if typ := (&page{flags: metaPageFlag}).typ(); typ != "meta" { 19 | t.Fatalf("exp=meta; got=%v", typ) 20 | } 21 | if typ := (&page{flags: freelistPageFlag}).typ(); typ != "freelist" { 22 | t.Fatalf("exp=freelist; got=%v", typ) 23 | } 24 | if typ := (&page{flags: 20000}).typ(); typ != "unknown<4e20>" { 25 | t.Fatalf("exp=unknown<4e20>; got=%v", typ) 26 | } 27 | } 28 | 29 | // Ensure that the hexdump debugging function doesn't blow up. 30 | func TestPage_dump(t *testing.T) { 31 | (&page{id: 256}).hexdump(16) 32 | } 33 | 34 | func TestPgids_merge(t *testing.T) { 35 | a := pgids{4, 5, 6, 10, 11, 12, 13, 27} 36 | b := pgids{1, 3, 8, 9, 25, 30} 37 | c := a.merge(b) 38 | if !reflect.DeepEqual(c, pgids{1, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 25, 27, 30}) { 39 | t.Errorf("mismatch: %v", c) 40 | } 41 | 42 | a = pgids{4, 5, 6, 10, 11, 12, 13, 27, 35, 36} 43 | b = pgids{8, 9, 25, 30} 44 | c = a.merge(b) 45 | if !reflect.DeepEqual(c, pgids{4, 5, 6, 8, 9, 10, 11, 12, 13, 25, 27, 30, 35, 36}) { 46 | t.Errorf("mismatch: %v", c) 47 | } 48 | } 49 | 50 | func TestPgids_merge_quick(t *testing.T) { 51 | if err := quick.Check(func(a, b pgids) bool { 52 | // Sort incoming lists. 53 | sort.Sort(a) 54 | sort.Sort(b) 55 | 56 | // Merge the two lists together. 57 | got := a.merge(b) 58 | 59 | // The expected value should be the two lists combined and sorted. 60 | exp := append(a, b...) 61 | sort.Sort(exp) 62 | 63 | if !reflect.DeepEqual(exp, got) { 64 | t.Errorf("\nexp=%+v\ngot=%+v\n", exp, got) 65 | return false 66 | } 67 | 68 | return true 69 | }, nil); err != nil { 70 | t.Fatal(err) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /vendor/github.com/boltdb/bolt/quick_test.go: -------------------------------------------------------------------------------- 1 | package bolt_test 2 | 3 | import ( 4 | "bytes" 5 | "flag" 6 | "fmt" 7 | "math/rand" 8 | "os" 9 | "reflect" 10 | "testing/quick" 11 | "time" 12 | ) 13 | 14 | // testing/quick defaults to 5 iterations and a random seed. 15 | // You can override these settings from the command line: 16 | // 17 | // -quick.count The number of iterations to perform. 18 | // -quick.seed The seed to use for randomizing. 19 | // -quick.maxitems The maximum number of items to insert into a DB. 20 | // -quick.maxksize The maximum size of a key. 21 | // -quick.maxvsize The maximum size of a value. 22 | // 23 | 24 | var qcount, qseed, qmaxitems, qmaxksize, qmaxvsize int 25 | 26 | func init() { 27 | flag.IntVar(&qcount, "quick.count", 5, "") 28 | flag.IntVar(&qseed, "quick.seed", int(time.Now().UnixNano())%100000, "") 29 | flag.IntVar(&qmaxitems, "quick.maxitems", 1000, "") 30 | flag.IntVar(&qmaxksize, "quick.maxksize", 1024, "") 31 | flag.IntVar(&qmaxvsize, "quick.maxvsize", 1024, "") 32 | flag.Parse() 33 | fmt.Fprintln(os.Stderr, "seed:", qseed) 34 | fmt.Fprintf(os.Stderr, "quick settings: count=%v, items=%v, ksize=%v, vsize=%v\n", qcount, qmaxitems, qmaxksize, qmaxvsize) 35 | } 36 | 37 | func qconfig() *quick.Config { 38 | return &quick.Config{ 39 | MaxCount: qcount, 40 | Rand: rand.New(rand.NewSource(int64(qseed))), 41 | } 42 | } 43 | 44 | type testdata []testdataitem 45 | 46 | func (t testdata) Len() int { return len(t) } 47 | func (t testdata) Swap(i, j int) { t[i], t[j] = t[j], t[i] } 48 | func (t testdata) Less(i, j int) bool { return bytes.Compare(t[i].Key, t[j].Key) == -1 } 49 | 50 | func (t testdata) Generate(rand *rand.Rand, size int) reflect.Value { 51 | n := rand.Intn(qmaxitems-1) + 1 52 | items := make(testdata, n) 53 | for i := 0; i < n; i++ { 54 | item := &items[i] 55 | item.Key = randByteSlice(rand, 1, qmaxksize) 56 | item.Value = randByteSlice(rand, 0, qmaxvsize) 57 | } 58 | return reflect.ValueOf(items) 59 | } 60 | 61 | type revtestdata []testdataitem 62 | 63 | func (t revtestdata) Len() int { return len(t) } 64 | func (t revtestdata) Swap(i, j int) { t[i], t[j] = t[j], t[i] } 65 | func (t revtestdata) Less(i, j int) bool { return bytes.Compare(t[i].Key, t[j].Key) == 1 } 66 | 67 | type testdataitem struct { 68 | Key []byte 69 | Value []byte 70 | } 71 | 72 | func randByteSlice(rand *rand.Rand, minSize, maxSize int) []byte { 73 | n := rand.Intn(maxSize-minSize) + minSize 74 | b := make([]byte, n) 75 | for i := 0; i < n; i++ { 76 | b[i] = byte(rand.Intn(255)) 77 | } 78 | return b 79 | } 80 | -------------------------------------------------------------------------------- /vendor/github.com/garyburd/redigo/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: false 3 | services: 4 | - redis-server 5 | 6 | go: 7 | - 1.4 8 | - 1.5 9 | - 1.6 10 | - tip 11 | 12 | script: 13 | - go get -t -v ./... 14 | - diff -u <(echo -n) <(gofmt -d .) 15 | - go vet $(go list ./... | grep -v /vendor/) 16 | - go test -v -race ./... 17 | -------------------------------------------------------------------------------- /vendor/github.com/garyburd/redigo/README.markdown: -------------------------------------------------------------------------------- 1 | Redigo 2 | ====== 3 | 4 | [![Build Status](https://travis-ci.org/garyburd/redigo.svg?branch=master)](https://travis-ci.org/garyburd/redigo) 5 | [![GoDoc](https://godoc.org/github.com/garyburd/redigo/redis?status.svg)](https://godoc.org/github.com/garyburd/redigo/redis) 6 | 7 | Redigo is a [Go](http://golang.org/) client for the [Redis](http://redis.io/) database. 8 | 9 | Features 10 | ------- 11 | 12 | * A [Print-like](http://godoc.org/github.com/garyburd/redigo/redis#hdr-Executing_Commands) API with support for all Redis commands. 13 | * [Pipelining](http://godoc.org/github.com/garyburd/redigo/redis#hdr-Pipelining), including pipelined transactions. 14 | * [Publish/Subscribe](http://godoc.org/github.com/garyburd/redigo/redis#hdr-Publish_and_Subscribe). 15 | * [Connection pooling](http://godoc.org/github.com/garyburd/redigo/redis#Pool). 16 | * [Script helper type](http://godoc.org/github.com/garyburd/redigo/redis#Script) with optimistic use of EVALSHA. 17 | * [Helper functions](http://godoc.org/github.com/garyburd/redigo/redis#hdr-Reply_Helpers) for working with command replies. 18 | 19 | Documentation 20 | ------------- 21 | 22 | - [API Reference](http://godoc.org/github.com/garyburd/redigo/redis) 23 | - [FAQ](https://github.com/garyburd/redigo/wiki/FAQ) 24 | 25 | Installation 26 | ------------ 27 | 28 | Install Redigo using the "go get" command: 29 | 30 | go get github.com/garyburd/redigo/redis 31 | 32 | The Go distribution is Redigo's only dependency. 33 | 34 | Related Projects 35 | ---------------- 36 | 37 | - [rafaeljusto/redigomock](https://godoc.org/github.com/rafaeljusto/redigomock) - A mock library for Redigo. 38 | - [chasex/redis-go-cluster](https://github.com/chasex/redis-go-cluster) - A Redis cluster client implementation. 39 | - [FZambia/go-sentinel](https://github.com/FZambia/go-sentinel) - Redis Sentinel support for Redigo 40 | - [PuerkitoBio/redisc](https://github.com/PuerkitoBio/redisc) - Redis Cluster client built on top of Redigo 41 | 42 | Contributing 43 | ------------ 44 | 45 | Send email to Gary Burd (address in GitHub profile) before doing any work on Redigo. 46 | 47 | License 48 | ------- 49 | 50 | Redigo is available under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html). 51 | -------------------------------------------------------------------------------- /vendor/github.com/garyburd/redigo/internal/commandinfo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package internal // import "github.com/garyburd/redigo/internal" 16 | 17 | import ( 18 | "strings" 19 | ) 20 | 21 | const ( 22 | WatchState = 1 << iota 23 | MultiState 24 | SubscribeState 25 | MonitorState 26 | ) 27 | 28 | type CommandInfo struct { 29 | Set, Clear int 30 | } 31 | 32 | var commandInfos = map[string]CommandInfo{ 33 | "WATCH": {Set: WatchState}, 34 | "UNWATCH": {Clear: WatchState}, 35 | "MULTI": {Set: MultiState}, 36 | "EXEC": {Clear: WatchState | MultiState}, 37 | "DISCARD": {Clear: WatchState | MultiState}, 38 | "PSUBSCRIBE": {Set: SubscribeState}, 39 | "SUBSCRIBE": {Set: SubscribeState}, 40 | "MONITOR": {Set: MonitorState}, 41 | } 42 | 43 | func init() { 44 | for n, ci := range commandInfos { 45 | commandInfos[strings.ToLower(n)] = ci 46 | } 47 | } 48 | 49 | func LookupCommandInfo(commandName string) CommandInfo { 50 | if ci, ok := commandInfos[commandName]; ok { 51 | return ci 52 | } 53 | return commandInfos[strings.ToUpper(commandName)] 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/garyburd/redigo/internal/commandinfo_test.go: -------------------------------------------------------------------------------- 1 | package internal 2 | 3 | import "testing" 4 | 5 | func TestLookupCommandInfo(t *testing.T) { 6 | for _, n := range []string{"watch", "WATCH", "wAtch"} { 7 | if LookupCommandInfo(n) == (CommandInfo{}) { 8 | t.Errorf("LookupCommandInfo(%q) = CommandInfo{}, expected non-zero value", n) 9 | } 10 | } 11 | } 12 | 13 | func benchmarkLookupCommandInfo(b *testing.B, names ...string) { 14 | for i := 0; i < b.N; i++ { 15 | for _, c := range names { 16 | LookupCommandInfo(c) 17 | } 18 | } 19 | } 20 | 21 | func BenchmarkLookupCommandInfoCorrectCase(b *testing.B) { 22 | benchmarkLookupCommandInfo(b, "watch", "WATCH", "monitor", "MONITOR") 23 | } 24 | 25 | func BenchmarkLookupCommandInfoMixedCase(b *testing.B) { 26 | benchmarkLookupCommandInfo(b, "wAtch", "WeTCH", "monItor", "MONiTOR") 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/garyburd/redigo/internal/redistest/testdb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | // Package redistest contains utilities for writing Redigo tests. 16 | package redistest 17 | 18 | import ( 19 | "errors" 20 | "time" 21 | 22 | "github.com/garyburd/redigo/redis" 23 | ) 24 | 25 | type testConn struct { 26 | redis.Conn 27 | } 28 | 29 | func (t testConn) Close() error { 30 | _, err := t.Conn.Do("SELECT", "9") 31 | if err != nil { 32 | return nil 33 | } 34 | _, err = t.Conn.Do("FLUSHDB") 35 | if err != nil { 36 | return err 37 | } 38 | return t.Conn.Close() 39 | } 40 | 41 | // Dial dials the local Redis server and selects database 9. To prevent 42 | // stomping on real data, DialTestDB fails if database 9 contains data. The 43 | // returned connection flushes database 9 on close. 44 | func Dial() (redis.Conn, error) { 45 | c, err := redis.DialTimeout("tcp", ":6379", 0, 1*time.Second, 1*time.Second) 46 | if err != nil { 47 | return nil, err 48 | } 49 | 50 | _, err = c.Do("SELECT", "9") 51 | if err != nil { 52 | c.Close() 53 | return nil, err 54 | } 55 | 56 | n, err := redis.Int(c.Do("DBSIZE")) 57 | if err != nil { 58 | c.Close() 59 | return nil, err 60 | } 61 | 62 | if n != 0 { 63 | c.Close() 64 | return nil, errors.New("database #9 is not empty, test can not continue") 65 | } 66 | 67 | return testConn{c}, nil 68 | } 69 | -------------------------------------------------------------------------------- /vendor/github.com/garyburd/redigo/redis/redis.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package redis 16 | 17 | // Error represents an error returned in a command reply. 18 | type Error string 19 | 20 | func (err Error) Error() string { return string(err) } 21 | 22 | // Conn represents a connection to a Redis server. 23 | type Conn interface { 24 | // Close closes the connection. 25 | Close() error 26 | 27 | // Err returns a non-nil value if the connection is broken. The returned 28 | // value is either the first non-nil value returned from the underlying 29 | // network connection or a protocol parsing error. Applications should 30 | // close broken connections. 31 | Err() error 32 | 33 | // Do sends a command to the server and returns the received reply. 34 | Do(commandName string, args ...interface{}) (reply interface{}, err error) 35 | 36 | // Send writes the command to the client's output buffer. 37 | Send(commandName string, args ...interface{}) error 38 | 39 | // Flush flushes the output buffer to the Redis server. 40 | Flush() error 41 | 42 | // Receive receives a single reply from the Redis server 43 | Receive() (reply interface{}, err error) 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/garyburd/redigo/redisx/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | // Package redisx contains experimental features for Redigo. Features in this 16 | // package may be modified or deleted at any time. 17 | package redisx // import "github.com/garyburd/redigo/redisx" 18 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-msgpack/codec/ext_dep_test.go: -------------------------------------------------------------------------------- 1 | // //+build ignore 2 | 3 | // Copyright (c) 2012, 2013 Ugorji Nwoke. All rights reserved. 4 | // Use of this source code is governed by a BSD-style license found in the LICENSE file. 5 | 6 | package codec 7 | 8 | // This file includes benchmarks which have dependencies on 3rdparty 9 | // packages (bson and vmihailenco/msgpack) which must be installed locally. 10 | // 11 | // To run the benchmarks including these 3rdparty packages, first 12 | // - Uncomment first line in this file (put // // in front of it) 13 | // - Get those packages: 14 | // go get github.com/vmihailenco/msgpack 15 | // go get labix.org/v2/mgo/bson 16 | // - Run: 17 | // go test -bi -bench=. 18 | 19 | import ( 20 | "testing" 21 | 22 | vmsgpack "gopkg.in/vmihailenco/msgpack.v2" 23 | "labix.org/v2/mgo/bson" 24 | ) 25 | 26 | func init() { 27 | benchCheckers = append(benchCheckers, 28 | benchChecker{"v-msgpack", fnVMsgpackEncodeFn, fnVMsgpackDecodeFn}, 29 | benchChecker{"bson", fnBsonEncodeFn, fnBsonDecodeFn}, 30 | ) 31 | } 32 | 33 | func fnVMsgpackEncodeFn(ts interface{}) ([]byte, error) { 34 | return vmsgpack.Marshal(ts) 35 | } 36 | 37 | func fnVMsgpackDecodeFn(buf []byte, ts interface{}) error { 38 | return vmsgpack.Unmarshal(buf, ts) 39 | } 40 | 41 | func fnBsonEncodeFn(ts interface{}) ([]byte, error) { 42 | return bson.Marshal(ts) 43 | } 44 | 45 | func fnBsonDecodeFn(buf []byte, ts interface{}) error { 46 | return bson.Unmarshal(buf, ts) 47 | } 48 | 49 | func Benchmark__Bson_______Encode(b *testing.B) { 50 | fnBenchmarkEncode(b, "bson", benchTs, fnBsonEncodeFn) 51 | } 52 | 53 | func Benchmark__Bson_______Decode(b *testing.B) { 54 | fnBenchmarkDecode(b, "bson", benchTs, fnBsonEncodeFn, fnBsonDecodeFn, fnBenchNewTs) 55 | } 56 | 57 | func Benchmark__VMsgpack___Encode(b *testing.B) { 58 | fnBenchmarkEncode(b, "v-msgpack", benchTs, fnVMsgpackEncodeFn) 59 | } 60 | 61 | func Benchmark__VMsgpack___Decode(b *testing.B) { 62 | fnBenchmarkDecode(b, "v-msgpack", benchTs, fnVMsgpackEncodeFn, fnVMsgpackDecodeFn, fnBenchNewTs) 63 | } 64 | 65 | func TestMsgpackPythonGenStreams(t *testing.T) { 66 | doTestMsgpackPythonGenStreams(t) 67 | } 68 | 69 | func TestMsgpackRpcSpecGoClientToPythonSvc(t *testing.T) { 70 | doTestMsgpackRpcSpecGoClientToPythonSvc(t) 71 | } 72 | 73 | func TestMsgpackRpcSpecPythonClientToGoSvc(t *testing.T) { 74 | doTestMsgpackRpcSpecPythonClientToGoSvc(t) 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.4 5 | - 1.5 6 | - 1.6 7 | - tip 8 | 9 | install: make deps 10 | script: 11 | - make integ 12 | 13 | notifications: 14 | flowdock: 15 | secure: fZrcf9rlh2IrQrlch1sHkn3YI7SKvjGnAl/zyV5D6NROe1Bbr6d3QRMuCXWWdhJHzjKmXk5rIzbqJhUc0PNF7YjxGNKSzqWMQ56KcvN1k8DzlqxpqkcA3Jbs6fXCWo2fssRtZ7hj/wOP1f5n6cc7kzHDt9dgaYJ6nO2fqNPJiTc= 16 | 17 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/Makefile: -------------------------------------------------------------------------------- 1 | DEPS = $(go list -f '{{range .TestImports}}{{.}} {{end}}' ./...) 2 | 3 | test: 4 | go test -timeout=30s ./... 5 | 6 | integ: test 7 | INTEG_TESTS=yes go test -timeout=3s -run=Integ ./... 8 | 9 | deps: 10 | go get -d -v ./... 11 | echo $(DEPS) | xargs -n1 go get -d 12 | 13 | cov: 14 | INTEG_TESTS=yes gocov test github.com/hashicorp/raft | gocov-html > /tmp/coverage.html 15 | open /tmp/coverage.html 16 | 17 | .PHONY: test cov integ deps 18 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/commands.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | // AppendEntriesRequest is the command used to append entries to the 4 | // replicated log. 5 | type AppendEntriesRequest struct { 6 | // Provide the current term and leader 7 | Term uint64 8 | Leader []byte 9 | 10 | // Provide the previous entries for integrity checking 11 | PrevLogEntry uint64 12 | PrevLogTerm uint64 13 | 14 | // New entries to commit 15 | Entries []*Log 16 | 17 | // Commit index on the leader 18 | LeaderCommitIndex uint64 19 | } 20 | 21 | // AppendEntriesResponse is the response returned from an 22 | // AppendEntriesRequest. 23 | type AppendEntriesResponse struct { 24 | // Newer term if leader is out of date 25 | Term uint64 26 | 27 | // Last Log is a hint to help accelerate rebuilding slow nodes 28 | LastLog uint64 29 | 30 | // We may not succeed if we have a conflicting entry 31 | Success bool 32 | 33 | // There are scenarios where this request didn't succeed 34 | // but there's no need to wait/back-off the next attempt. 35 | NoRetryBackoff bool 36 | } 37 | 38 | // RequestVoteRequest is the command used by a candidate to ask a Raft peer 39 | // for a vote in an election. 40 | type RequestVoteRequest struct { 41 | // Provide the term and our id 42 | Term uint64 43 | Candidate []byte 44 | 45 | // Used to ensure safety 46 | LastLogIndex uint64 47 | LastLogTerm uint64 48 | } 49 | 50 | // RequestVoteResponse is the response returned from a RequestVoteRequest. 51 | type RequestVoteResponse struct { 52 | // Newer term if leader is out of date 53 | Term uint64 54 | 55 | // Return the peers, so that a node can shutdown on removal 56 | Peers []byte 57 | 58 | // Is the vote granted 59 | Granted bool 60 | } 61 | 62 | // InstallSnapshotRequest is the command sent to a Raft peer to bootstrap its 63 | // log (and state machine) from a snapshot on another peer. 64 | type InstallSnapshotRequest struct { 65 | Term uint64 66 | Leader []byte 67 | 68 | // These are the last index/term included in the snapshot 69 | LastLogIndex uint64 70 | LastLogTerm uint64 71 | 72 | // Peer Set in the snapshot 73 | Peers []byte 74 | 75 | // Size of the snapshot 76 | Size int64 77 | } 78 | 79 | // InstallSnapshotResponse is the response returned from an 80 | // InstallSnapshotRequest. 81 | type InstallSnapshotResponse struct { 82 | Term uint64 83 | Success bool 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/discard_snapshot.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | ) 7 | 8 | // DiscardSnapshotStore is used to successfully snapshot while 9 | // always discarding the snapshot. This is useful for when the 10 | // log should be truncated but no snapshot should be retained. 11 | // This should never be used for production use, and is only 12 | // suitable for testing. 13 | type DiscardSnapshotStore struct{} 14 | 15 | type DiscardSnapshotSink struct{} 16 | 17 | // NewDiscardSnapshotStore is used to create a new DiscardSnapshotStore. 18 | func NewDiscardSnapshotStore() *DiscardSnapshotStore { 19 | return &DiscardSnapshotStore{} 20 | } 21 | 22 | func (d *DiscardSnapshotStore) Create(index, term uint64, peers []byte) (SnapshotSink, error) { 23 | return &DiscardSnapshotSink{}, nil 24 | } 25 | 26 | func (d *DiscardSnapshotStore) List() ([]*SnapshotMeta, error) { 27 | return nil, nil 28 | } 29 | 30 | func (d *DiscardSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error) { 31 | return nil, nil, fmt.Errorf("open is not supported") 32 | } 33 | 34 | func (d *DiscardSnapshotSink) Write(b []byte) (int, error) { 35 | return len(b), nil 36 | } 37 | 38 | func (d *DiscardSnapshotSink) Close() error { 39 | return nil 40 | } 41 | 42 | func (d *DiscardSnapshotSink) ID() string { 43 | return "discard" 44 | } 45 | 46 | func (d *DiscardSnapshotSink) Cancel() error { 47 | return nil 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/discard_snapshot_test.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | import "testing" 4 | 5 | func TestDiscardSnapshotStoreImpl(t *testing.T) { 6 | var impl interface{} = &DiscardSnapshotStore{} 7 | if _, ok := impl.(SnapshotStore); !ok { 8 | t.Fatalf("DiscardSnapshotStore not a SnapshotStore") 9 | } 10 | } 11 | 12 | func TestDiscardSnapshotSinkImpl(t *testing.T) { 13 | var impl interface{} = &DiscardSnapshotSink{} 14 | if _, ok := impl.(SnapshotSink); !ok { 15 | t.Fatalf("DiscardSnapshotSink not a SnapshotSink") 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/fsm.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | import ( 4 | "io" 5 | ) 6 | 7 | // FSM provides an interface that can be implemented by 8 | // clients to make use of the replicated log. 9 | type FSM interface { 10 | // Apply log is invoked once a log entry is committed. 11 | // It returns a value which will be made available in the 12 | // ApplyFuture returned by Raft.Apply method if that 13 | // method was called on the same Raft node as the FSM. 14 | Apply(*Log) interface{} 15 | 16 | // Snapshot is used to support log compaction. This call should 17 | // return an FSMSnapshot which can be used to save a point-in-time 18 | // snapshot of the FSM. Apply and Snapshot are not called in multiple 19 | // threads, but Apply will be called concurrently with Persist. This means 20 | // the FSM should be implemented in a fashion that allows for concurrent 21 | // updates while a snapshot is happening. 22 | Snapshot() (FSMSnapshot, error) 23 | 24 | // Restore is used to restore an FSM from a snapshot. It is not called 25 | // concurrently with any other command. The FSM must discard all previous 26 | // state. 27 | Restore(io.ReadCloser) error 28 | } 29 | 30 | // FSMSnapshot is returned by an FSM in response to a Snapshot 31 | // It must be safe to invoke FSMSnapshot methods with concurrent 32 | // calls to Apply. 33 | type FSMSnapshot interface { 34 | // Persist should dump all necessary state to the WriteCloser 'sink', 35 | // and call sink.Close() when finished or call sink.Cancel() on error. 36 | Persist(sink SnapshotSink) error 37 | 38 | // Release is invoked when we are finished with the snapshot. 39 | Release() 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/future_test.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | import ( 4 | "errors" 5 | "testing" 6 | ) 7 | 8 | func TestDeferFutureSuccess(t *testing.T) { 9 | var f deferError 10 | f.init() 11 | f.respond(nil) 12 | if err := f.Error(); err != nil { 13 | t.Fatalf("unexpected error result; got %#v want nil", err) 14 | } 15 | if err := f.Error(); err != nil { 16 | t.Fatalf("unexpected error result; got %#v want nil", err) 17 | } 18 | } 19 | 20 | func TestDeferFutureError(t *testing.T) { 21 | want := errors.New("x") 22 | var f deferError 23 | f.init() 24 | f.respond(want) 25 | if got := f.Error(); got != want { 26 | t.Fatalf("unexpected error result; got %#v want %#v", got, want) 27 | } 28 | if got := f.Error(); got != want { 29 | t.Fatalf("unexpected error result; got %#v want %#v", got, want) 30 | } 31 | } 32 | 33 | func TestDeferFutureConcurrent(t *testing.T) { 34 | // Food for the race detector. 35 | want := errors.New("x") 36 | var f deferError 37 | f.init() 38 | go f.respond(want) 39 | if got := f.Error(); got != want { 40 | t.Errorf("unexpected error result; got %#v want %#v", got, want) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/inmem_transport_test.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestInmemTransportImpl(t *testing.T) { 8 | var inm interface{} = &InmemTransport{} 9 | if _, ok := inm.(Transport); !ok { 10 | t.Fatalf("InmemTransport is not a Transport") 11 | } 12 | if _, ok := inm.(LoopbackTransport); !ok { 13 | t.Fatalf("InmemTransport is not a Loopback Transport") 14 | } 15 | if _, ok := inm.(WithPeers); !ok { 16 | t.Fatalf("InmemTransport is not a WithPeers Transport") 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/log.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | // LogType describes various types of log entries. 4 | type LogType uint8 5 | 6 | const ( 7 | // LogCommand is applied to a user FSM. 8 | LogCommand LogType = iota 9 | 10 | // LogNoop is used to assert leadership. 11 | LogNoop 12 | 13 | // LogAddPeer is used to add a new peer. 14 | LogAddPeer 15 | 16 | // LogRemovePeer is used to remove an existing peer. 17 | LogRemovePeer 18 | 19 | // LogBarrier is used to ensure all preceding operations have been 20 | // applied to the FSM. It is similar to LogNoop, but instead of returning 21 | // once committed, it only returns once the FSM manager acks it. Otherwise 22 | // it is possible there are operations committed but not yet applied to 23 | // the FSM. 24 | LogBarrier 25 | ) 26 | 27 | // Log entries are replicated to all members of the Raft cluster 28 | // and form the heart of the replicated state machine. 29 | type Log struct { 30 | // Index holds the index of the log entry. 31 | Index uint64 32 | 33 | // Term holds the election term of the log entry. 34 | Term uint64 35 | 36 | // Type holds the type of the log entry. 37 | Type LogType 38 | 39 | // Data holds the log entry's type-specific data. 40 | Data []byte 41 | 42 | // peer is not exported since it is not transmitted, only used 43 | // internally to construct the Data field. 44 | peer string 45 | } 46 | 47 | // LogStore is used to provide an interface for storing 48 | // and retrieving logs in a durable fashion. 49 | type LogStore interface { 50 | // FirstIndex returns the first index written. 0 for no entries. 51 | FirstIndex() (uint64, error) 52 | 53 | // LastIndex returns the last index written. 0 for no entries. 54 | LastIndex() (uint64, error) 55 | 56 | // GetLog gets a log entry at a given index. 57 | GetLog(index uint64, log *Log) error 58 | 59 | // StoreLog stores a log entry. 60 | StoreLog(log *Log) error 61 | 62 | // StoreLogs stores multiple log entries. 63 | StoreLogs(logs []*Log) error 64 | 65 | // DeleteRange deletes a range of log entries. The range is inclusive. 66 | DeleteRange(min, max uint64) error 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/log_cache.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | // LogCache wraps any LogStore implementation to provide an 9 | // in-memory ring buffer. This is used to cache access to 10 | // the recently written entries. For implementations that do not 11 | // cache themselves, this can provide a substantial boost by 12 | // avoiding disk I/O on recent entries. 13 | type LogCache struct { 14 | store LogStore 15 | 16 | cache []*Log 17 | l sync.RWMutex 18 | } 19 | 20 | // NewLogCache is used to create a new LogCache with the 21 | // given capacity and backend store. 22 | func NewLogCache(capacity int, store LogStore) (*LogCache, error) { 23 | if capacity <= 0 { 24 | return nil, fmt.Errorf("capacity must be positive") 25 | } 26 | c := &LogCache{ 27 | store: store, 28 | cache: make([]*Log, capacity), 29 | } 30 | return c, nil 31 | } 32 | 33 | func (c *LogCache) GetLog(idx uint64, log *Log) error { 34 | // Check the buffer for an entry 35 | c.l.RLock() 36 | cached := c.cache[idx%uint64(len(c.cache))] 37 | c.l.RUnlock() 38 | 39 | // Check if entry is valid 40 | if cached != nil && cached.Index == idx { 41 | *log = *cached 42 | return nil 43 | } 44 | 45 | // Forward request on cache miss 46 | return c.store.GetLog(idx, log) 47 | } 48 | 49 | func (c *LogCache) StoreLog(log *Log) error { 50 | return c.StoreLogs([]*Log{log}) 51 | } 52 | 53 | func (c *LogCache) StoreLogs(logs []*Log) error { 54 | // Insert the logs into the ring buffer 55 | c.l.Lock() 56 | for _, l := range logs { 57 | c.cache[l.Index%uint64(len(c.cache))] = l 58 | } 59 | c.l.Unlock() 60 | 61 | return c.store.StoreLogs(logs) 62 | } 63 | 64 | func (c *LogCache) FirstIndex() (uint64, error) { 65 | return c.store.FirstIndex() 66 | } 67 | 68 | func (c *LogCache) LastIndex() (uint64, error) { 69 | return c.store.LastIndex() 70 | } 71 | 72 | func (c *LogCache) DeleteRange(min, max uint64) error { 73 | // Invalidate the cache on deletes 74 | c.l.Lock() 75 | c.cache = make([]*Log, len(c.cache)) 76 | c.l.Unlock() 77 | 78 | return c.store.DeleteRange(min, max) 79 | } 80 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/log_cache_test.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestLogCache(t *testing.T) { 8 | store := NewInmemStore() 9 | c, _ := NewLogCache(16, store) 10 | 11 | // Insert into the in-mem store 12 | for i := 0; i < 32; i++ { 13 | log := &Log{Index: uint64(i) + 1} 14 | store.StoreLog(log) 15 | } 16 | 17 | // Check the indexes 18 | if idx, _ := c.FirstIndex(); idx != 1 { 19 | t.Fatalf("bad: %d", idx) 20 | } 21 | if idx, _ := c.LastIndex(); idx != 32 { 22 | t.Fatalf("bad: %d", idx) 23 | } 24 | 25 | // Try get log with a miss 26 | var out Log 27 | err := c.GetLog(1, &out) 28 | if err != nil { 29 | t.Fatalf("err: %v", err) 30 | } 31 | if out.Index != 1 { 32 | t.Fatalf("bad: %#v", out) 33 | } 34 | 35 | // Store logs 36 | l1 := &Log{Index: 33} 37 | l2 := &Log{Index: 34} 38 | err = c.StoreLogs([]*Log{l1, l2}) 39 | if err != nil { 40 | t.Fatalf("err: %v", err) 41 | } 42 | 43 | if idx, _ := c.LastIndex(); idx != 34 { 44 | t.Fatalf("bad: %d", idx) 45 | } 46 | 47 | // Check that it wrote-through 48 | err = store.GetLog(33, &out) 49 | if err != nil { 50 | t.Fatalf("err: %v", err) 51 | } 52 | err = store.GetLog(34, &out) 53 | if err != nil { 54 | t.Fatalf("err: %v", err) 55 | } 56 | 57 | // Delete in the backend 58 | err = store.DeleteRange(33, 34) 59 | if err != nil { 60 | t.Fatalf("err: %v", err) 61 | } 62 | 63 | // Should be in the ring buffer 64 | err = c.GetLog(33, &out) 65 | if err != nil { 66 | t.Fatalf("err: %v", err) 67 | } 68 | err = c.GetLog(34, &out) 69 | if err != nil { 70 | t.Fatalf("err: %v", err) 71 | } 72 | 73 | // Purge the ring buffer 74 | err = c.DeleteRange(33, 34) 75 | if err != nil { 76 | t.Fatalf("err: %v", err) 77 | } 78 | 79 | // Should not be in the ring buffer 80 | err = c.GetLog(33, &out) 81 | if err != ErrLogNotFound { 82 | t.Fatalf("err: %v", err) 83 | } 84 | err = c.GetLog(34, &out) 85 | if err != ErrLogNotFound { 86 | t.Fatalf("err: %v", err) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/peer_test.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | import ( 4 | "io/ioutil" 5 | "os" 6 | "testing" 7 | ) 8 | 9 | func TestJSONPeers(t *testing.T) { 10 | // Create a test dir 11 | dir, err := ioutil.TempDir("", "raft") 12 | if err != nil { 13 | t.Fatalf("err: %v ", err) 14 | } 15 | defer os.RemoveAll(dir) 16 | 17 | // Create the store 18 | _, trans := NewInmemTransport("") 19 | store := NewJSONPeers(dir, trans) 20 | 21 | // Try a read, should get nothing 22 | peers, err := store.Peers() 23 | if err != nil { 24 | t.Fatalf("err: %v", err) 25 | } 26 | if len(peers) != 0 { 27 | t.Fatalf("peers: %v", peers) 28 | } 29 | 30 | // Initialize some peers 31 | newPeers := []string{NewInmemAddr(), NewInmemAddr(), NewInmemAddr()} 32 | if err := store.SetPeers(newPeers); err != nil { 33 | t.Fatalf("err: %v", err) 34 | } 35 | 36 | // Try a read, should peers 37 | peers, err = store.Peers() 38 | if err != nil { 39 | t.Fatalf("err: %v", err) 40 | } 41 | if len(peers) != 3 { 42 | t.Fatalf("peers: %v", peers) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/snapshot.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | import ( 4 | "io" 5 | ) 6 | 7 | // SnapshotMeta is for metadata of a snapshot. 8 | type SnapshotMeta struct { 9 | ID string // ID is opaque to the store, and is used for opening 10 | Index uint64 11 | Term uint64 12 | Peers []byte 13 | Size int64 14 | } 15 | 16 | // SnapshotStore interface is used to allow for flexible implementations 17 | // of snapshot storage and retrieval. For example, a client could implement 18 | // a shared state store such as S3, allowing new nodes to restore snapshots 19 | // without streaming from the leader. 20 | type SnapshotStore interface { 21 | // Create is used to begin a snapshot at a given index and term, 22 | // with the current peer set already encoded. 23 | Create(index, term uint64, peers []byte) (SnapshotSink, error) 24 | 25 | // List is used to list the available snapshots in the store. 26 | // It should return then in descending order, with the highest index first. 27 | List() ([]*SnapshotMeta, error) 28 | 29 | // Open takes a snapshot ID and provides a ReadCloser. Once close is 30 | // called it is assumed the snapshot is no longer needed. 31 | Open(id string) (*SnapshotMeta, io.ReadCloser, error) 32 | } 33 | 34 | // SnapshotSink is returned by StartSnapshot. The FSM will Write state 35 | // to the sink and call Close on completion. On error, Cancel will be invoked. 36 | type SnapshotSink interface { 37 | io.WriteCloser 38 | ID() string 39 | Cancel() error 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/stable.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | // StableStore is used to provide stable storage 4 | // of key configurations to ensure safety. 5 | type StableStore interface { 6 | Set(key []byte, val []byte) error 7 | 8 | // Get returns the value for key, or an empty byte slice if key was not found. 9 | Get(key []byte) ([]byte, error) 10 | 11 | SetUint64(key []byte, val uint64) error 12 | 13 | // GetUint64 returns the uint64 value for key, or 0 if key was not found. 14 | GetUint64(key []byte) (uint64, error) 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/raft/tcp_transport_test.go: -------------------------------------------------------------------------------- 1 | package raft 2 | 3 | import ( 4 | "net" 5 | "testing" 6 | ) 7 | 8 | func TestTCPTransport_BadAddr(t *testing.T) { 9 | _, err := NewTCPTransportWithLogger("0.0.0.0:0", nil, 1, 0, newTestLogger(t)) 10 | if err != errNotAdvertisable { 11 | t.Fatalf("err: %v", err) 12 | } 13 | } 14 | 15 | func TestTCPTransport_WithAdvertise(t *testing.T) { 16 | addr := &net.TCPAddr{IP: []byte{127, 0, 0, 1}, Port: 12345} 17 | trans, err := NewTCPTransportWithLogger("0.0.0.0:0", addr, 1, 0, newTestLogger(t)) 18 | if err != nil { 19 | t.Fatalf("err: %v", err) 20 | } 21 | if trans.LocalAddr() != "127.0.0.1:12345" { 22 | t.Fatalf("bad: %v", trans.LocalAddr()) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/.gitignore: -------------------------------------------------------------------------------- 1 | /.test 2 | /otto/otto 3 | /otto/otto-* 4 | /test/test-*.js 5 | /test/tester 6 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/DESIGN.markdown: -------------------------------------------------------------------------------- 1 | * Designate the filename of "anonymous" source code by the hash (md5/sha1, etc.) 2 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Robert Krimen 2 | 3 | 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: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | 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. 8 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test test-race test-release release release-check test-262 2 | .PHONY: parser 3 | .PHONY: otto assets underscore 4 | 5 | TESTS := \ 6 | ~ 7 | 8 | TEST := -v --run 9 | TEST := -v 10 | TEST := -v --run Test\($(subst $(eval) ,\|,$(TESTS))\) 11 | TEST := . 12 | 13 | test: parser inline.go 14 | go test -i 15 | go test $(TEST) 16 | @echo PASS 17 | 18 | parser: 19 | $(MAKE) -C parser 20 | 21 | inline.go: inline.pl 22 | ./$< > $@ 23 | 24 | ################# 25 | # release, test # 26 | ################# 27 | 28 | release: test-race test-release 29 | for package in . parser token ast file underscore registry; do (cd $$package && godocdown --signature > README.markdown); done 30 | @echo \*\*\* make release-check 31 | @echo PASS 32 | 33 | release-check: .test 34 | $(MAKE) -C test build test 35 | $(MAKE) -C .test/test262 build test 36 | @echo PASS 37 | 38 | test-262: .test 39 | $(MAKE) -C .test/test262 build test 40 | @echo PASS 41 | 42 | test-release: 43 | go test -i 44 | go test 45 | 46 | test-race: 47 | go test -race -i 48 | go test -race 49 | 50 | ################################# 51 | # otto, assets, underscore, ... # 52 | ################################# 53 | 54 | otto: 55 | $(MAKE) -C otto 56 | 57 | assets: 58 | mkdir -p .assets 59 | for file in underscore/test/*.js; do tr "\`" "_" < $$file > .assets/`basename $$file`; done 60 | 61 | underscore: 62 | $(MAKE) -C $@ 63 | 64 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/ast/comments_test.go: -------------------------------------------------------------------------------- 1 | package ast 2 | 3 | import ( 4 | "github.com/robertkrimen/otto/file" 5 | "testing" 6 | ) 7 | 8 | func TestCommentMap(t *testing.T) { 9 | statement := &EmptyStatement{file.Idx(1)} 10 | comment := &Comment{1, "test", LEADING} 11 | 12 | cm := CommentMap{} 13 | cm.AddComment(statement, comment) 14 | 15 | if cm.Size() != 1 { 16 | t.Errorf("the number of comments is %v, not 1", cm.Size()) 17 | } 18 | 19 | if len(cm[statement]) != 1 { 20 | t.Errorf("the number of comments is %v, not 1", cm.Size()) 21 | } 22 | 23 | if cm[statement][0].Text != "test" { 24 | t.Errorf("the text is %v, not \"test\"", cm[statement][0].Text) 25 | } 26 | } 27 | 28 | func TestCommentMap_move(t *testing.T) { 29 | statement1 := &EmptyStatement{file.Idx(1)} 30 | statement2 := &EmptyStatement{file.Idx(2)} 31 | comment := &Comment{1, "test", LEADING} 32 | 33 | cm := CommentMap{} 34 | cm.AddComment(statement1, comment) 35 | 36 | if cm.Size() != 1 { 37 | t.Errorf("the number of comments is %v, not 1", cm.Size()) 38 | } 39 | 40 | if len(cm[statement1]) != 1 { 41 | t.Errorf("the number of comments is %v, not 1", cm.Size()) 42 | } 43 | 44 | if len(cm[statement2]) != 0 { 45 | t.Errorf("the number of comments is %v, not 0", cm.Size()) 46 | } 47 | 48 | cm.MoveComments(statement1, statement2, LEADING) 49 | 50 | if cm.Size() != 1 { 51 | t.Errorf("the number of comments is %v, not 1", cm.Size()) 52 | } 53 | 54 | if len(cm[statement2]) != 1 { 55 | t.Errorf("the number of comments is %v, not 1", cm.Size()) 56 | } 57 | 58 | if len(cm[statement1]) != 0 { 59 | t.Errorf("the number of comments is %v, not 0", cm.Size()) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/builtin_boolean.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | // Boolean 4 | 5 | func builtinBoolean(call FunctionCall) Value { 6 | return toValue_bool(call.Argument(0).bool()) 7 | } 8 | 9 | func builtinNewBoolean(self *_object, argumentList []Value) Value { 10 | return toValue_object(self.runtime.newBoolean(valueOfArrayIndex(argumentList, 0))) 11 | } 12 | 13 | func builtinBoolean_toString(call FunctionCall) Value { 14 | value := call.This 15 | if !value.IsBoolean() { 16 | // Will throw a TypeError if ThisObject is not a Boolean 17 | value = call.thisClassObject("Boolean").primitiveValue() 18 | } 19 | return toValue_string(value.string()) 20 | } 21 | 22 | func builtinBoolean_valueOf(call FunctionCall) Value { 23 | value := call.This 24 | if !value.IsBoolean() { 25 | value = call.thisClassObject("Boolean").primitiveValue() 26 | } 27 | return value 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/builtin_regexp.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // RegExp 8 | 9 | func builtinRegExp(call FunctionCall) Value { 10 | pattern := call.Argument(0) 11 | flags := call.Argument(1) 12 | if object := pattern._object(); object != nil { 13 | if object.class == "RegExp" && flags.IsUndefined() { 14 | return pattern 15 | } 16 | } 17 | return toValue_object(call.runtime.newRegExp(pattern, flags)) 18 | } 19 | 20 | func builtinNewRegExp(self *_object, argumentList []Value) Value { 21 | return toValue_object(self.runtime.newRegExp( 22 | valueOfArrayIndex(argumentList, 0), 23 | valueOfArrayIndex(argumentList, 1), 24 | )) 25 | } 26 | 27 | func builtinRegExp_toString(call FunctionCall) Value { 28 | thisObject := call.thisObject() 29 | source := thisObject.get("source").string() 30 | flags := []byte{} 31 | if thisObject.get("global").bool() { 32 | flags = append(flags, 'g') 33 | } 34 | if thisObject.get("ignoreCase").bool() { 35 | flags = append(flags, 'i') 36 | } 37 | if thisObject.get("multiline").bool() { 38 | flags = append(flags, 'm') 39 | } 40 | return toValue_string(fmt.Sprintf("/%s/%s", source, flags)) 41 | } 42 | 43 | func builtinRegExp_exec(call FunctionCall) Value { 44 | thisObject := call.thisObject() 45 | target := call.Argument(0).string() 46 | match, result := execRegExp(thisObject, target) 47 | if !match { 48 | return nullValue 49 | } 50 | return toValue_object(execResultToArray(call.runtime, target, result)) 51 | } 52 | 53 | func builtinRegExp_test(call FunctionCall) Value { 54 | thisObject := call.thisObject() 55 | target := call.Argument(0).string() 56 | match, _ := execRegExp(thisObject, target) 57 | return toValue_bool(match) 58 | } 59 | 60 | func builtinRegExp_compile(call FunctionCall) Value { 61 | // This (useless) function is deprecated, but is here to provide some 62 | // semblance of compatibility. 63 | // Caveat emptor: it may not be around for long. 64 | return Value{} 65 | } 66 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/clone_test.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestCloneGetterSetter(t *testing.T) { 8 | vm := New() 9 | 10 | vm.Run(`var x = Object.create(null, { 11 | x: { 12 | get: function() {}, 13 | set: function() {}, 14 | }, 15 | })`) 16 | 17 | vm.Copy() 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/cmpl.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "github.com/robertkrimen/otto/ast" 5 | "github.com/robertkrimen/otto/file" 6 | ) 7 | 8 | type _file struct { 9 | name string 10 | src string 11 | base int // This will always be 1 or greater 12 | } 13 | 14 | type _compiler struct { 15 | file *file.File 16 | program *ast.Program 17 | } 18 | 19 | func (cmpl *_compiler) parse() *_nodeProgram { 20 | if cmpl.program != nil { 21 | cmpl.file = cmpl.program.File 22 | } 23 | return cmpl._parse(cmpl.program) 24 | } 25 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/cmpl_test.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/robertkrimen/otto/parser" 7 | ) 8 | 9 | func Test_cmpl(t *testing.T) { 10 | tt(t, func() { 11 | vm := New() 12 | 13 | test := func(src string, expect ...interface{}) { 14 | program, err := parser.ParseFile(nil, "", src, 0) 15 | is(err, nil) 16 | { 17 | program := cmpl_parse(program) 18 | value := vm.runtime.cmpl_evaluate_nodeProgram(program, false) 19 | if len(expect) > 0 { 20 | is(value, expect[0]) 21 | } 22 | } 23 | } 24 | 25 | test(``, Value{}) 26 | 27 | test(`var abc = 1; abc;`, 1) 28 | 29 | test(`var abc = 1 + 1; abc;`, 2) 30 | 31 | test(`1 + 2;`, 3) 32 | }) 33 | } 34 | 35 | func TestParse_cmpl(t *testing.T) { 36 | tt(t, func() { 37 | 38 | test := func(src string) { 39 | program, err := parser.ParseFile(nil, "", src, 0) 40 | is(err, nil) 41 | is(cmpl_parse(program), "!=", nil) 42 | } 43 | 44 | test(``) 45 | 46 | test(`var abc = 1; abc;`) 47 | 48 | test(` 49 | function abc() { 50 | return; 51 | } 52 | `) 53 | }) 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/console.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | ) 8 | 9 | func formatForConsole(argumentList []Value) string { 10 | output := []string{} 11 | for _, argument := range argumentList { 12 | output = append(output, fmt.Sprintf("%v", argument)) 13 | } 14 | return strings.Join(output, " ") 15 | } 16 | 17 | func builtinConsole_log(call FunctionCall) Value { 18 | fmt.Fprintln(os.Stdout, formatForConsole(call.ArgumentList)) 19 | return Value{} 20 | } 21 | 22 | func builtinConsole_error(call FunctionCall) Value { 23 | fmt.Fprintln(os.Stdout, formatForConsole(call.ArgumentList)) 24 | return Value{} 25 | } 26 | 27 | // Nothing happens. 28 | func builtinConsole_dir(call FunctionCall) Value { 29 | return Value{} 30 | } 31 | 32 | func builtinConsole_time(call FunctionCall) Value { 33 | return Value{} 34 | } 35 | 36 | func builtinConsole_timeEnd(call FunctionCall) Value { 37 | return Value{} 38 | } 39 | 40 | func builtinConsole_trace(call FunctionCall) Value { 41 | return Value{} 42 | } 43 | 44 | func builtinConsole_assert(call FunctionCall) Value { 45 | return Value{} 46 | } 47 | 48 | func (runtime *_runtime) newConsole() *_object { 49 | 50 | return newConsoleObject(runtime) 51 | } 52 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/dbg.go: -------------------------------------------------------------------------------- 1 | // This file was AUTOMATICALLY GENERATED by dbg-import (smuggol) for github.com/robertkrimen/dbg 2 | 3 | package otto 4 | 5 | import ( 6 | Dbg "github.com/robertkrimen/otto/dbg" 7 | ) 8 | 9 | var dbg, dbgf = Dbg.New() 10 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/documentation_test.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func ExampleSynopsis() { 8 | 9 | vm := New() 10 | vm.Run(` 11 | abc = 2 + 2; 12 | console.log("The value of abc is " + abc); // 4 13 | `) 14 | 15 | value, _ := vm.Get("abc") 16 | { 17 | value, _ := value.ToInteger() 18 | fmt.Println(value) 19 | } 20 | 21 | vm.Set("def", 11) 22 | vm.Run(` 23 | console.log("The value of def is " + def); 24 | `) 25 | 26 | vm.Set("xyzzy", "Nothing happens.") 27 | vm.Run(` 28 | console.log(xyzzy.length); 29 | `) 30 | 31 | value, _ = vm.Run("xyzzy.length") 32 | { 33 | value, _ := value.ToInteger() 34 | fmt.Println(value) 35 | } 36 | 37 | value, err := vm.Run("abcdefghijlmnopqrstuvwxyz.length") 38 | fmt.Println(value) 39 | fmt.Println(err) 40 | 41 | vm.Set("sayHello", func(call FunctionCall) Value { 42 | fmt.Printf("Hello, %s.\n", call.Argument(0).String()) 43 | return UndefinedValue() 44 | }) 45 | 46 | vm.Set("twoPlus", func(call FunctionCall) Value { 47 | right, _ := call.Argument(0).ToInteger() 48 | result, _ := vm.ToValue(2 + right) 49 | return result 50 | }) 51 | 52 | value, _ = vm.Run(` 53 | sayHello("Xyzzy"); 54 | sayHello(); 55 | 56 | result = twoPlus(2.0); 57 | `) 58 | fmt.Println(value) 59 | 60 | // Output: 61 | // The value of abc is 4 62 | // 4 63 | // The value of def is 11 64 | // 16 65 | // 16 66 | // undefined 67 | // ReferenceError: 'abcdefghijlmnopqrstuvwxyz' is not defined 68 | // Hello, Xyzzy. 69 | // Hello, undefined. 70 | // 4 71 | } 72 | 73 | func ExampleConsole() { 74 | 75 | vm := New() 76 | console := map[string]interface{}{ 77 | "log": func(call FunctionCall) Value { 78 | fmt.Println("console.log:", formatForConsole(call.ArgumentList)) 79 | return UndefinedValue() 80 | }, 81 | } 82 | 83 | err := vm.Set("console", console) 84 | 85 | value, err := vm.Run(` 86 | console.log("Hello, World."); 87 | `) 88 | fmt.Println(value) 89 | fmt.Println(err) 90 | 91 | // Output: 92 | // console.log: Hello, World. 93 | // undefined 94 | // 95 | } 96 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/error_native_test.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | // this is its own file because the tests in it rely on the line numbers of 8 | // some of the functions defined here. putting it in with the rest of the 9 | // tests would probably be annoying. 10 | 11 | func TestErrorContextNative(t *testing.T) { 12 | tt(t, func() { 13 | vm := New() 14 | 15 | vm.Set("N", func(c FunctionCall) Value { 16 | v, err := c.Argument(0).Call(NullValue()) 17 | if err != nil { 18 | panic(err) 19 | } 20 | return v 21 | }) 22 | 23 | s, _ := vm.Compile("test.js", ` 24 | function F() { throw new Error('wow'); } 25 | function G() { return N(F); } 26 | `) 27 | 28 | vm.Run(s) 29 | 30 | f1, _ := vm.Get("G") 31 | _, err := f1.Call(NullValue()) 32 | err1 := err.(*Error) 33 | is(err1.message, "wow") 34 | is(len(err1.trace), 3) 35 | is(err1.trace[0].location(), "F (test.js:2:29)") 36 | is(err1.trace[1].location(), "github.com/robertkrimen/otto.TestErrorContextNative.func1.1 (error_native_test.go:15)") 37 | is(err1.trace[2].location(), "G (test.js:3:26)") 38 | }) 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/file/README.markdown: -------------------------------------------------------------------------------- 1 | # file 2 | -- 3 | import "github.com/robertkrimen/otto/file" 4 | 5 | Package file encapsulates the file abstractions used by the ast & parser. 6 | 7 | ## Usage 8 | 9 | #### type File 10 | 11 | ```go 12 | type File struct { 13 | } 14 | ``` 15 | 16 | 17 | #### func NewFile 18 | 19 | ```go 20 | func NewFile(filename, src string, base int) *File 21 | ``` 22 | 23 | #### func (*File) Base 24 | 25 | ```go 26 | func (fl *File) Base() int 27 | ``` 28 | 29 | #### func (*File) Name 30 | 31 | ```go 32 | func (fl *File) Name() string 33 | ``` 34 | 35 | #### func (*File) Source 36 | 37 | ```go 38 | func (fl *File) Source() string 39 | ``` 40 | 41 | #### type FileSet 42 | 43 | ```go 44 | type FileSet struct { 45 | } 46 | ``` 47 | 48 | A FileSet represents a set of source files. 49 | 50 | #### func (*FileSet) AddFile 51 | 52 | ```go 53 | func (self *FileSet) AddFile(filename, src string) int 54 | ``` 55 | AddFile adds a new file with the given filename and src. 56 | 57 | This an internal method, but exported for cross-package use. 58 | 59 | #### func (*FileSet) File 60 | 61 | ```go 62 | func (self *FileSet) File(idx Idx) *File 63 | ``` 64 | 65 | #### func (*FileSet) Position 66 | 67 | ```go 68 | func (self *FileSet) Position(idx Idx) *Position 69 | ``` 70 | Position converts an Idx in the FileSet into a Position. 71 | 72 | #### type Idx 73 | 74 | ```go 75 | type Idx int 76 | ``` 77 | 78 | Idx is a compact encoding of a source position within a file set. It can be 79 | converted into a Position for a more convenient, but much larger, 80 | representation. 81 | 82 | #### type Position 83 | 84 | ```go 85 | type Position struct { 86 | Filename string // The filename where the error occurred, if any 87 | Offset int // The src offset 88 | Line int // The line number, starting at 1 89 | Column int // The column number, starting at 1 (The character count) 90 | 91 | } 92 | ``` 93 | 94 | Position describes an arbitrary source position including the filename, line, 95 | and column location. 96 | 97 | #### func (*Position) String 98 | 99 | ```go 100 | func (self *Position) String() string 101 | ``` 102 | String returns a string in one of several forms: 103 | 104 | file:line:column A valid position with filename 105 | line:column A valid position without filename 106 | file An invalid position with filename 107 | - An invalid position without filename 108 | 109 | -- 110 | **godocdown** http://github.com/robertkrimen/godocdown 111 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/function_stack_test.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | // this is its own file because the tests in it rely on the line numbers of 8 | // some of the functions defined here. putting it in with the rest of the 9 | // tests would probably be annoying. 10 | 11 | func TestFunction_stack(t *testing.T) { 12 | tt(t, func() { 13 | vm := New() 14 | 15 | s, _ := vm.Compile("fake.js", `function X(fn1, fn2, fn3) { fn1(fn2, fn3); }`) 16 | vm.Run(s) 17 | 18 | expected := []_frame{ 19 | {native: true, nativeFile: "function_stack_test.go", nativeLine: 30, offset: 0, callee: "github.com/robertkrimen/otto.TestFunction_stack.func1.2"}, 20 | {native: true, nativeFile: "function_stack_test.go", nativeLine: 25, offset: 0, callee: "github.com/robertkrimen/otto.TestFunction_stack.func1.1"}, 21 | {native: false, nativeFile: "", nativeLine: 0, offset: 29, callee: "X", file: s.program.file}, 22 | {native: false, nativeFile: "", nativeLine: 0, offset: 29, callee: "X", file: s.program.file}, 23 | } 24 | 25 | vm.Set("A", func(c FunctionCall) Value { 26 | c.Argument(0).Call(UndefinedValue()) 27 | return UndefinedValue() 28 | }) 29 | 30 | vm.Set("B", func(c FunctionCall) Value { 31 | depth := 0 32 | for scope := c.Otto.runtime.scope; scope != nil; scope = scope.outer { 33 | is(scope.frame, expected[depth]) 34 | depth++ 35 | } 36 | 37 | is(depth, 4) 38 | 39 | return UndefinedValue() 40 | }) 41 | 42 | x, _ := vm.Get("X") 43 | a, _ := vm.Get("A") 44 | b, _ := vm.Get("B") 45 | 46 | x.Call(UndefinedValue(), x, a, b) 47 | }) 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/otto/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build 2 | 3 | build: 4 | go build -a 5 | -gxc build-darwin-386 -a 6 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/otto/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "io/ioutil" 7 | "os" 8 | 9 | "github.com/robertkrimen/otto" 10 | "github.com/robertkrimen/otto/underscore" 11 | ) 12 | 13 | var flag_underscore *bool = flag.Bool("underscore", true, "Load underscore into the runtime environment") 14 | 15 | func readSource(filename string) ([]byte, error) { 16 | if filename == "" || filename == "-" { 17 | return ioutil.ReadAll(os.Stdin) 18 | } 19 | return ioutil.ReadFile(filename) 20 | } 21 | 22 | func main() { 23 | flag.Parse() 24 | 25 | if !*flag_underscore { 26 | underscore.Disable() 27 | } 28 | 29 | err := func() error { 30 | src, err := readSource(flag.Arg(0)) 31 | if err != nil { 32 | return err 33 | } 34 | 35 | vm := otto.New() 36 | _, err = vm.Run(src) 37 | return err 38 | }() 39 | if err != nil { 40 | switch err := err.(type) { 41 | case *otto.Error: 42 | fmt.Print(err.String()) 43 | default: 44 | fmt.Println(err) 45 | } 46 | os.Exit(64) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/otto_error_test.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestOttoError(t *testing.T) { 8 | tt(t, func() { 9 | vm := New() 10 | 11 | _, err := vm.Run(`throw "Xyzzy"`) 12 | is(err, "Xyzzy") 13 | 14 | _, err = vm.Run(`throw new TypeError()`) 15 | is(err, "TypeError") 16 | 17 | _, err = vm.Run(`throw new TypeError("Nothing happens.")`) 18 | is(err, "TypeError: Nothing happens.") 19 | 20 | _, err = ToValue([]byte{}) 21 | is(err, "TypeError: invalid value (slice): missing runtime: [] ([]uint8)") 22 | 23 | _, err = vm.Run(` 24 | (function(){ 25 | return abcdef.length 26 | })() 27 | `) 28 | is(err, "ReferenceError: 'abcdef' is not defined") 29 | 30 | _, err = vm.Run(` 31 | function start() { 32 | } 33 | 34 | start() 35 | 36 | xyzzy() 37 | `) 38 | is(err, "ReferenceError: 'xyzzy' is not defined") 39 | 40 | _, err = vm.Run(` 41 | // Just a comment 42 | 43 | xyzzy 44 | `) 45 | is(err, "ReferenceError: 'xyzzy' is not defined") 46 | 47 | }) 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/panic_test.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func Test_panic(t *testing.T) { 8 | tt(t, func() { 9 | test, _ := test() 10 | 11 | // Test that property.value is set to something if writable is set 12 | // to something 13 | test(` 14 | var abc = []; 15 | Object.defineProperty(abc, "0", { writable: false }); 16 | Object.defineProperty(abc, "0", { writable: false }); 17 | "0" in abc; 18 | `, true) 19 | 20 | test(`raise: 21 | var abc = []; 22 | Object.defineProperty(abc, "0", { writable: false }); 23 | Object.defineProperty(abc, "0", { value: false, writable: false }); 24 | `, "TypeError") 25 | 26 | // Test that a regular expression can contain \c0410 (CYRILLIC CAPITAL LETTER A) 27 | // without panicking 28 | test(` 29 | var abc = 0x0410; 30 | var def = String.fromCharCode(abc); 31 | new RegExp("\\c" + def).exec(def); 32 | `, "null") 33 | 34 | // Test transforming a transformable regular expression without a panic 35 | test(` 36 | new RegExp("\\u0000"); 37 | new RegExp("\\undefined").test("undefined"); 38 | `, true) 39 | }) 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/parser/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test 2 | 3 | test: 4 | go test 5 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/parser/dbg.go: -------------------------------------------------------------------------------- 1 | // This file was AUTOMATICALLY GENERATED by dbg-import (smuggol) for github.com/robertkrimen/dbg 2 | 3 | package parser 4 | 5 | import ( 6 | Dbg "github.com/robertkrimen/otto/dbg" 7 | ) 8 | 9 | var dbg, dbgf = Dbg.New() 10 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/parser/scope.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "github.com/robertkrimen/otto/ast" 5 | ) 6 | 7 | type _scope struct { 8 | outer *_scope 9 | allowIn bool 10 | inIteration bool 11 | inSwitch bool 12 | inFunction bool 13 | declarationList []ast.Declaration 14 | 15 | labels []string 16 | } 17 | 18 | func (self *_parser) openScope() { 19 | self.scope = &_scope{ 20 | outer: self.scope, 21 | allowIn: true, 22 | } 23 | } 24 | 25 | func (self *_parser) closeScope() { 26 | self.scope = self.scope.outer 27 | } 28 | 29 | func (self *_scope) declare(declaration ast.Declaration) { 30 | self.declarationList = append(self.declarationList, declaration) 31 | } 32 | 33 | func (self *_scope) hasLabel(name string) bool { 34 | for _, label := range self.labels { 35 | if label == name { 36 | return true 37 | } 38 | } 39 | if self.outer != nil && !self.inFunction { 40 | // Crossing a function boundary to look for a label is verboten 41 | return self.outer.hasLabel(name) 42 | } 43 | return false 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/parser_test.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestPersistence(t *testing.T) { 8 | tt(t, func() { 9 | test, _ := test() 10 | 11 | test(` 12 | function abc() { return 1; } 13 | abc.toString(); 14 | `, "function abc() { return 1; }") 15 | 16 | test(` 17 | function def() { return 3.14159; } 18 | [ abc.toString(), def.toString() ]; 19 | `, "function abc() { return 1; },function def() { return 3.14159; }") 20 | 21 | test(` 22 | eval("function ghi() { return 'ghi' }"); 23 | [ abc.toString(), def.toString(), ghi.toString() ]; 24 | `, "function abc() { return 1; },function def() { return 3.14159; },function ghi() { return 'ghi' }") 25 | 26 | test(` 27 | [ abc.toString(), def.toString(), ghi.toString() ]; 28 | `, "function abc() { return 1; },function def() { return 3.14159; },function ghi() { return 'ghi' }") 29 | 30 | test(`/* 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | */`, UndefinedValue()) 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/registry/README.markdown: -------------------------------------------------------------------------------- 1 | # registry 2 | -- 3 | import "github.com/robertkrimen/otto/registry" 4 | 5 | Package registry is an expirmental package to facillitate altering the otto 6 | runtime via import. 7 | 8 | This interface can change at any time. 9 | 10 | ## Usage 11 | 12 | #### func Apply 13 | 14 | ```go 15 | func Apply(callback func(Entry)) 16 | ``` 17 | 18 | #### type Entry 19 | 20 | ```go 21 | type Entry struct { 22 | } 23 | ``` 24 | 25 | 26 | #### func Register 27 | 28 | ```go 29 | func Register(source func() string) *Entry 30 | ``` 31 | 32 | #### func (*Entry) Disable 33 | 34 | ```go 35 | func (self *Entry) Disable() 36 | ``` 37 | 38 | #### func (*Entry) Enable 39 | 40 | ```go 41 | func (self *Entry) Enable() 42 | ``` 43 | 44 | #### func (Entry) Source 45 | 46 | ```go 47 | func (self Entry) Source() string 48 | ``` 49 | 50 | -- 51 | **godocdown** http://github.com/robertkrimen/godocdown 52 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/registry/registry.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package registry is an expirmental package to facillitate altering the otto runtime via import. 3 | 4 | This interface can change at any time. 5 | */ 6 | package registry 7 | 8 | var registry []*Entry = make([]*Entry, 0) 9 | 10 | type Entry struct { 11 | active bool 12 | source func() string 13 | } 14 | 15 | func newEntry(source func() string) *Entry { 16 | return &Entry{ 17 | active: true, 18 | source: source, 19 | } 20 | } 21 | 22 | func (self *Entry) Enable() { 23 | self.active = true 24 | } 25 | 26 | func (self *Entry) Disable() { 27 | self.active = false 28 | } 29 | 30 | func (self Entry) Source() string { 31 | return self.source() 32 | } 33 | 34 | func Apply(callback func(Entry)) { 35 | for _, entry := range registry { 36 | if !entry.active { 37 | continue 38 | } 39 | callback(*entry) 40 | } 41 | } 42 | 43 | func Register(source func() string) *Entry { 44 | entry := newEntry(source) 45 | registry = append(registry, entry) 46 | return entry 47 | } 48 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/repl/autocompleter.go: -------------------------------------------------------------------------------- 1 | package repl 2 | 3 | import ( 4 | "regexp" 5 | "strings" 6 | 7 | "github.com/robertkrimen/otto" 8 | ) 9 | 10 | type autoCompleter struct { 11 | vm *otto.Otto 12 | } 13 | 14 | var lastExpressionRegex = regexp.MustCompile(`[a-zA-Z0-9]([a-zA-Z0-9\.]*[a-zA-Z0-9])?\.?$`) 15 | 16 | func (a *autoCompleter) Do(line []rune, pos int) ([][]rune, int) { 17 | lastExpression := lastExpressionRegex.FindString(string(line)) 18 | 19 | bits := strings.Split(lastExpression, ".") 20 | 21 | first := bits[:len(bits)-1] 22 | last := bits[len(bits)-1] 23 | 24 | var l []string 25 | 26 | if len(first) == 0 { 27 | c := a.vm.Context() 28 | 29 | l = make([]string, len(c.Symbols)) 30 | 31 | i := 0 32 | for k := range c.Symbols { 33 | l[i] = k 34 | i++ 35 | } 36 | } else { 37 | r, err := a.vm.Eval(strings.Join(bits[:len(bits)-1], ".")) 38 | if err != nil { 39 | return nil, 0 40 | } 41 | 42 | if o := r.Object(); o != nil { 43 | for _, v := range o.KeysByParent() { 44 | l = append(l, v...) 45 | } 46 | } 47 | } 48 | 49 | var r [][]rune 50 | for _, s := range l { 51 | if strings.HasPrefix(s, last) { 52 | r = append(r, []rune(strings.TrimPrefix(s, last))) 53 | } 54 | } 55 | 56 | return r, len(last) 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/result.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import () 4 | 5 | type _resultKind int 6 | 7 | const ( 8 | resultNormal _resultKind = iota 9 | resultReturn 10 | resultBreak 11 | resultContinue 12 | ) 13 | 14 | type _result struct { 15 | kind _resultKind 16 | value Value 17 | target string 18 | } 19 | 20 | func newReturnResult(value Value) _result { 21 | return _result{resultReturn, value, ""} 22 | } 23 | 24 | func newContinueResult(target string) _result { 25 | return _result{resultContinue, emptyValue, target} 26 | } 27 | 28 | func newBreakResult(target string) _result { 29 | return _result{resultBreak, emptyValue, target} 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/scope.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | // _scope: 4 | // entryFile 5 | // entryIdx 6 | // top? 7 | // outer => nil 8 | 9 | // _stash: 10 | // lexical 11 | // variable 12 | // 13 | // _thisStash (ObjectEnvironment) 14 | // _fnStash 15 | // _dclStash 16 | 17 | // An ECMA-262 ExecutionContext 18 | type _scope struct { 19 | lexical _stash 20 | variable _stash 21 | this *_object 22 | eval bool // Replace this with kind? 23 | outer *_scope 24 | depth int 25 | 26 | frame _frame 27 | } 28 | 29 | func newScope(lexical _stash, variable _stash, this *_object) *_scope { 30 | return &_scope{ 31 | lexical: lexical, 32 | variable: variable, 33 | this: this, 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/script_test.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestScript(t *testing.T) { 8 | tt(t, func() { 9 | vm := New() 10 | 11 | script, err := vm.Compile("xyzzy", `var abc; if (!abc) abc = 0; abc += 2; abc;`) 12 | is(err, nil) 13 | 14 | str := script.String() 15 | is(str, "// xyzzy\nvar abc; if (!abc) abc = 0; abc += 2; abc;") 16 | 17 | value, err := vm.Run(script) 18 | is(err, nil) 19 | is(value, 2) 20 | 21 | if true { 22 | return 23 | } 24 | 25 | tmp, err := script.marshalBinary() 26 | is(err, nil) 27 | is(len(tmp), 1228) 28 | 29 | { 30 | script := &Script{} 31 | err = script.unmarshalBinary(tmp) 32 | is(err, nil) 33 | 34 | is(script.String(), str) 35 | 36 | value, err = vm.Run(script) 37 | is(err, nil) 38 | is(value, 4) 39 | 40 | tmp, err = script.marshalBinary() 41 | is(err, nil) 42 | is(len(tmp), 1228) 43 | } 44 | 45 | { 46 | script := &Script{} 47 | err = script.unmarshalBinary(tmp) 48 | is(err, nil) 49 | 50 | is(script.String(), str) 51 | 52 | value, err := vm.Run(script) 53 | is(err, nil) 54 | is(value, 6) 55 | 56 | tmp, err = script.marshalBinary() 57 | is(err, nil) 58 | is(len(tmp), 1228) 59 | } 60 | 61 | { 62 | version := scriptVersion 63 | scriptVersion = "bogus" 64 | 65 | script := &Script{} 66 | err = script.unmarshalBinary(tmp) 67 | is(err, "version mismatch") 68 | 69 | is(script.String(), "// \n") 70 | is(script.version, "") 71 | is(script.program == nil, true) 72 | is(script.filename, "") 73 | is(script.src, "") 74 | 75 | scriptVersion = version 76 | } 77 | }) 78 | } 79 | 80 | func TestFunctionCall_CallerLocation(t *testing.T) { 81 | tt(t, func() { 82 | vm := New() 83 | vm.Set("loc", func(call FunctionCall) Value { 84 | return toValue(call.CallerLocation()) 85 | }) 86 | script, err := vm.Compile("somefile.js", `var where = loc();`) 87 | is(err, nil) 88 | _, err = vm.Run(script) 89 | is(err, nil) 90 | where, err := vm.Get("where") 91 | is(err, nil) 92 | is(where, "somefile.js:1:13") 93 | }) 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/test/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test fetch clean build err report 2 | 3 | TESTER := tester 4 | 5 | test: $(TESTER) 6 | for test in test-*.js; do ./$^ -test=true $$test 1>/dev/null || exit 1; done 7 | @echo PASS 8 | 9 | report: $(TESTER) 10 | ./$^ -report | grep -v "MT READY" 11 | 12 | fetch: $(TESTER) 13 | ./$^ fetch 14 | 15 | build: 16 | go build -a -o $(TESTER) 17 | 18 | $(TESTER): tester.go 19 | $(MAKE) build 20 | 21 | clean: 22 | rm -f test-*.js 23 | rm -f $(TESTER) 24 | 25 | err: $(TESTER) 26 | for test in test-*.js; do ./$^ $$test; done 2>$@ 27 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/token/Makefile: -------------------------------------------------------------------------------- 1 | token_const.go: tokenfmt 2 | ./$^ | gofmt > $@ 3 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/type_boolean.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "strconv" 5 | ) 6 | 7 | func (runtime *_runtime) newBooleanObject(value Value) *_object { 8 | return runtime.newPrimitiveObject("Boolean", toValue_bool(value.bool())) 9 | } 10 | 11 | func booleanToString(value bool) string { 12 | return strconv.FormatBool(value) 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/type_error.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | func (rt *_runtime) newErrorObject(name string, message Value, stackFramesToPop int) *_object { 4 | self := rt.newClassObject("Error") 5 | if message.IsDefined() { 6 | msg := message.string() 7 | self.defineProperty("message", toValue_string(msg), 0111, false) 8 | self.value = newError(rt, name, stackFramesToPop, msg) 9 | } else { 10 | self.value = newError(rt, name, stackFramesToPop) 11 | } 12 | 13 | self.defineOwnProperty("stack", _property{ 14 | value: _propertyGetSet{ 15 | rt.newNativeFunction("get", "internal", 0, func(FunctionCall) Value { 16 | return toValue_string(self.value.(_error).formatWithStack()) 17 | }), 18 | &_nilGetSetObject, 19 | }, 20 | mode: modeConfigureMask & modeOnMask, 21 | }, false) 22 | 23 | return self 24 | } 25 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/type_go_map.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "reflect" 5 | ) 6 | 7 | func (runtime *_runtime) newGoMapObject(value reflect.Value) *_object { 8 | self := runtime.newObject() 9 | self.class = "Object" // TODO Should this be something else? 10 | self.objectClass = _classGoMap 11 | self.value = _newGoMapObject(value) 12 | return self 13 | } 14 | 15 | type _goMapObject struct { 16 | value reflect.Value 17 | keyKind reflect.Kind 18 | valueKind reflect.Kind 19 | } 20 | 21 | func _newGoMapObject(value reflect.Value) *_goMapObject { 22 | if value.Kind() != reflect.Map { 23 | dbgf("%/panic//%@: %v != reflect.Map", value.Kind()) 24 | } 25 | self := &_goMapObject{ 26 | value: value, 27 | keyKind: value.Type().Key().Kind(), 28 | valueKind: value.Type().Elem().Kind(), 29 | } 30 | return self 31 | } 32 | 33 | func (self _goMapObject) toKey(name string) reflect.Value { 34 | reflectValue, err := stringToReflectValue(name, self.keyKind) 35 | if err != nil { 36 | panic(err) 37 | } 38 | return reflectValue 39 | } 40 | 41 | func (self _goMapObject) toValue(value Value) reflect.Value { 42 | reflectValue, err := value.toReflectValue(self.valueKind) 43 | if err != nil { 44 | panic(err) 45 | } 46 | return reflectValue 47 | } 48 | 49 | func goMapGetOwnProperty(self *_object, name string) *_property { 50 | object := self.value.(*_goMapObject) 51 | value := object.value.MapIndex(object.toKey(name)) 52 | if value.IsValid() { 53 | return &_property{self.runtime.toValue(value.Interface()), 0111} 54 | } 55 | 56 | return nil 57 | } 58 | 59 | func goMapEnumerate(self *_object, all bool, each func(string) bool) { 60 | object := self.value.(*_goMapObject) 61 | keys := object.value.MapKeys() 62 | for _, key := range keys { 63 | if !each(toValue(key).String()) { 64 | return 65 | } 66 | } 67 | } 68 | 69 | func goMapDefineOwnProperty(self *_object, name string, descriptor _property, throw bool) bool { 70 | object := self.value.(*_goMapObject) 71 | // TODO ...or 0222 72 | if descriptor.mode != 0111 { 73 | return self.runtime.typeErrorResult(throw) 74 | } 75 | if !descriptor.isDataDescriptor() { 76 | return self.runtime.typeErrorResult(throw) 77 | } 78 | object.value.SetMapIndex(object.toKey(name), object.toValue(descriptor.value.(Value))) 79 | return true 80 | } 81 | 82 | func goMapDelete(self *_object, name string, throw bool) bool { 83 | object := self.value.(*_goMapObject) 84 | object.value.SetMapIndex(object.toKey(name), reflect.Value{}) 85 | // FIXME 86 | return true 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/type_go_slice_test.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import "testing" 4 | 5 | type GoSliceTest []int 6 | 7 | func (s GoSliceTest) Sum() int { 8 | sum := 0 9 | for _, v := range s { 10 | sum += v 11 | } 12 | return sum 13 | } 14 | 15 | func TestGoSlice(t *testing.T) { 16 | tt(t, func() { 17 | test, vm := test() 18 | vm.Set("TestSlice", GoSliceTest{1, 2, 3}) 19 | is(test(`TestSlice.length`).export(), 3) 20 | is(test(`TestSlice[1]`).export(), 2) 21 | is(test(`TestSlice.Sum()`).export(), 6) 22 | }) 23 | } 24 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/type_number.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | func (runtime *_runtime) newNumberObject(value Value) *_object { 4 | return runtime.newPrimitiveObject("Number", value.numberValue()) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/underscore/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: source 2 | 3 | source: source.go 4 | 5 | underscore.js: 6 | curl -kL http://underscorejs.org/underscore.js > $@ 7 | 8 | source.go: underscore.js 9 | go-bindata -f underscore -p underscore -u true < $< 2>/dev/null | grep -v '^//' | gofmt > $@ 10 | head -4 $< >> $@ 11 | mv $< .. 12 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/underscore/README.markdown: -------------------------------------------------------------------------------- 1 | # underscore 2 | -- 3 | import "github.com/robertkrimen/otto/underscore" 4 | 5 | Package underscore contains the source for the JavaScript utility-belt library. 6 | 7 | import ( 8 | _ "github.com/robertkrimen/otto/underscore" 9 | ) 10 | // Every Otto runtime will now include underscore 11 | 12 | http://underscorejs.org 13 | 14 | https://github.com/documentcloud/underscore 15 | 16 | By importing this package, you'll automatically load underscore every time you 17 | create a new Otto runtime. 18 | 19 | To prevent this behavior, you can do the following: 20 | 21 | import ( 22 | "github.com/robertkrimen/otto/underscore" 23 | ) 24 | 25 | func init() { 26 | underscore.Disable() 27 | } 28 | 29 | ## Usage 30 | 31 | #### func Disable 32 | 33 | ```go 34 | func Disable() 35 | ``` 36 | Disable underscore runtime inclusion. 37 | 38 | #### func Enable 39 | 40 | ```go 41 | func Enable() 42 | ``` 43 | Enable underscore runtime inclusion. 44 | 45 | #### func Source 46 | 47 | ```go 48 | func Source() string 49 | ``` 50 | Source returns the underscore source. 51 | 52 | -- 53 | **godocdown** http://github.com/robertkrimen/godocdown 54 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/underscore/testify: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | my $underscore_test = shift @ARGV || ""; 7 | if (!-d $underscore_test) { 8 | print <<_END_; 9 | Usage: 10 | 11 | testify ./underscore/test 12 | 13 | # Should look something like: 14 | arrays.js 15 | chaining.js 16 | collections.js 17 | functions.js 18 | index.html 19 | objects.js 20 | speed.js 21 | utility.js 22 | vendor 23 | 24 | _END_ 25 | if ($underscore_test) { 26 | die "!: Not a directory: $underscore_test\n" 27 | } 28 | exit; 29 | } 30 | 31 | chdir $underscore_test or die "!: $!"; 32 | 33 | my @js = <*.js>; 34 | 35 | for my $file (@js) { 36 | open my $fh, '<', $file or die "!: $!"; 37 | my $tests = join "", <$fh>; 38 | my @tests = $tests =~ m/ 39 | ^(\s{2}test\(.*? 40 | ^\s{2}}\);)$ 41 | /mgxs; 42 | close $fh; 43 | next unless @tests; 44 | print "$file: ", scalar(@tests), "\n"; 45 | my $underscore_name = "underscore_$file"; 46 | $underscore_name =~ s/.js$//; 47 | my $go_file = "${underscore_name}_test.go"; 48 | $go_file =~ s/.js$/.go/; 49 | open $fh, '>', $go_file or die "!: $!"; 50 | 51 | $fh->print(<<_END_); 52 | package otto 53 | 54 | import ( 55 | "testing" 56 | ) 57 | 58 | _END_ 59 | 60 | my $count = 0; 61 | for my $test (@tests) { 62 | $test =~ s/`([^`]+)`/<$1>/g; 63 | my ($name) = $test =~ m/^\s*test\(['"]([^'"]+)['"]/; 64 | $fh->print(<<_END_); 65 | // $name 66 | func Test_${underscore_name}_$count(t *testing.T) { 67 | tt(t, func(){ 68 | test := underscoreTest() 69 | 70 | test(` 71 | $test 72 | `) 73 | }) 74 | } 75 | 76 | _END_ 77 | $count++; 78 | } 79 | } 80 | 81 | # test('#779 - delimeters are applied to unescaped text.', 1, function() { 82 | # var template = _.template('<<\nx\n>>', null, {evaluate: /<<(.*?)>>/g}); 83 | # strictEqual(template(), '<<\nx\n>>'); 84 | # }); 85 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/underscore/underscore.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package underscore contains the source for the JavaScript utility-belt library. 3 | 4 | import ( 5 | _ "github.com/robertkrimen/otto/underscore" 6 | ) 7 | // Every Otto runtime will now include underscore 8 | 9 | http://underscorejs.org 10 | 11 | https://github.com/documentcloud/underscore 12 | 13 | By importing this package, you'll automatically load underscore every time you create a new Otto runtime. 14 | 15 | To prevent this behavior, you can do the following: 16 | 17 | import ( 18 | "github.com/robertkrimen/otto/underscore" 19 | ) 20 | 21 | func init() { 22 | underscore.Disable() 23 | } 24 | 25 | */ 26 | package underscore 27 | 28 | import ( 29 | "github.com/robertkrimen/otto/registry" 30 | ) 31 | 32 | var entry *registry.Entry = registry.Register(func() string { 33 | return Source() 34 | }) 35 | 36 | // Enable underscore runtime inclusion. 37 | func Enable() { 38 | entry.Enable() 39 | } 40 | 41 | // Disable underscore runtime inclusion. 42 | func Disable() { 43 | entry.Disable() 44 | } 45 | 46 | // Source returns the underscore source. 47 | func Source() string { 48 | return string(underscore()) 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/underscore_chaining_test.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | // map/flatten/reduce 8 | func Test_underscore_chaining_0(t *testing.T) { 9 | tt(t, func() { 10 | test, _ := test_() 11 | 12 | test(` 13 | test("map/flatten/reduce", function() { 14 | var lyrics = [ 15 | "I'm a lumberjack and I'm okay", 16 | "I sleep all night and I work all day", 17 | "He's a lumberjack and he's okay", 18 | "He sleeps all night and he works all day" 19 | ]; 20 | var counts = _(lyrics).chain() 21 | .map(function(line) { return line.split(''); }) 22 | .flatten() 23 | .reduce(function(hash, l) { 24 | hash[l] = hash[l] || 0; 25 | hash[l]++; 26 | return hash; 27 | }, {}).value(); 28 | ok(counts['a'] == 16 && counts['e'] == 10, 'counted all the letters in the song'); 29 | }); 30 | `) 31 | }) 32 | } 33 | 34 | // select/reject/sortBy 35 | func Test_underscore_chaining_1(t *testing.T) { 36 | tt(t, func() { 37 | test, _ := test_() 38 | 39 | test(` 40 | test("select/reject/sortBy", function() { 41 | var numbers = [1,2,3,4,5,6,7,8,9,10]; 42 | numbers = _(numbers).chain().select(function(n) { 43 | return n % 2 == 0; 44 | }).reject(function(n) { 45 | return n % 4 == 0; 46 | }).sortBy(function(n) { 47 | return -n; 48 | }).value(); 49 | equal(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers"); 50 | }); 51 | `) 52 | }) 53 | } 54 | 55 | // select/reject/sortBy in functional style 56 | func Test_underscore_chaining_2(t *testing.T) { 57 | tt(t, func() { 58 | test, _ := test_() 59 | 60 | test(` 61 | test("select/reject/sortBy in functional style", function() { 62 | var numbers = [1,2,3,4,5,6,7,8,9,10]; 63 | numbers = _.chain(numbers).select(function(n) { 64 | return n % 2 == 0; 65 | }).reject(function(n) { 66 | return n % 4 == 0; 67 | }).sortBy(function(n) { 68 | return -n; 69 | }).value(); 70 | equal(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers"); 71 | }); 72 | `) 73 | }) 74 | } 75 | 76 | // reverse/concat/unshift/pop/map 77 | func Test_underscore_chaining_3(t *testing.T) { 78 | tt(t, func() { 79 | test, _ := test_() 80 | 81 | test(` 82 | test("reverse/concat/unshift/pop/map", function() { 83 | var numbers = [1,2,3,4,5]; 84 | numbers = _(numbers).chain() 85 | .reverse() 86 | .concat([5, 5, 5]) 87 | .unshift(17) 88 | .pop() 89 | .map(function(n){ return n * 2; }) 90 | .value(); 91 | equal(numbers.join(', '), "34, 10, 8, 6, 4, 2, 10, 10", 'can chain together array functions.'); 92 | }); 93 | `) 94 | }) 95 | } 96 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/value_boolean.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | "reflect" 7 | ) 8 | 9 | func (value Value) bool() bool { 10 | if value.kind == valueBoolean { 11 | return value.value.(bool) 12 | } 13 | if value.IsUndefined() { 14 | return false 15 | } 16 | if value.IsNull() { 17 | return false 18 | } 19 | switch value := value.value.(type) { 20 | case bool: 21 | return value 22 | case int, int8, int16, int32, int64: 23 | return 0 != reflect.ValueOf(value).Int() 24 | case uint, uint8, uint16, uint32, uint64: 25 | return 0 != reflect.ValueOf(value).Uint() 26 | case float32: 27 | return 0 != value 28 | case float64: 29 | if math.IsNaN(value) || value == 0 { 30 | return false 31 | } 32 | return true 33 | case string: 34 | return 0 != len(value) 35 | } 36 | if value.IsObject() { 37 | return true 38 | } 39 | panic(fmt.Errorf("toBoolean(%T)", value.value)) 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/robertkrimen/otto/value_primitive.go: -------------------------------------------------------------------------------- 1 | package otto 2 | 3 | func toStringPrimitive(value Value) Value { 4 | return _toPrimitive(value, defaultValueHintString) 5 | } 6 | 7 | func toNumberPrimitive(value Value) Value { 8 | return _toPrimitive(value, defaultValueHintNumber) 9 | } 10 | 11 | func toPrimitive(value Value) Value { 12 | return _toPrimitive(value, defaultValueNoHint) 13 | } 14 | 15 | func _toPrimitive(value Value, hint _defaultValueHint) Value { 16 | switch value.kind { 17 | case valueNull, valueUndefined, valueNumber, valueString, valueBoolean: 18 | return value 19 | case valueObject: 20 | return value._object().DefaultValue(hint) 21 | } 22 | panic(hereBeDragons(value.kind, value)) 23 | } 24 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/btree/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/buntdb/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/buntdb/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/buntdb/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidwall/summitdb/bc639291bb251f21b05c7e87526faa28f5f8ae23/vendor/github.com/tidwall/buntdb/logo.png -------------------------------------------------------------------------------- /vendor/github.com/tidwall/collate/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/collate/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/collate/collate_test.go: -------------------------------------------------------------------------------- 1 | package collate 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | func TestString(t *testing.T) { 9 | if len(SupportedLangs()) == 0 { 10 | t.Fatal("expected something greater than zero") 11 | } 12 | less := IndexString("ENGLISH_CI") 13 | if !less("a", "b") { 14 | t.Fatal("expected true, got false") 15 | } 16 | } 17 | 18 | func ExampleIndexJSON() { 19 | var jsonA = `{"name":{"last":"Miller"}}` 20 | var jsonB = `{"name":{"last":"anderson"}}` 21 | less := IndexJSON("ENGLISH_CI", "name.last") 22 | fmt.Printf("%t\n", less(jsonA, jsonB)) 23 | fmt.Printf("%t\n", less(jsonB, jsonA)) 24 | // Output: 25 | // false 26 | // true 27 | } 28 | 29 | func ExampleIndexString() { 30 | var nameA = "Miller" 31 | var nameB = "anderson" 32 | less := IndexString("ENGLISH_CI") 33 | fmt.Printf("%t\n", less(nameA, nameB)) 34 | fmt.Printf("%t\n", less(nameB, nameA)) 35 | // Output: 36 | // false 37 | // true 38 | } 39 | 40 | func ExampleSpanish() { 41 | less := IndexString("SPANISH_CI") 42 | fmt.Printf("%t\n", less("Hola", "hola")) 43 | fmt.Printf("%t\n", less("hola", "Hola")) 44 | // Output: 45 | // false 46 | // false 47 | } 48 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/finn/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/finn/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/finn/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidwall/summitdb/bc639291bb251f21b05c7e87526faa28f5f8ae23/vendor/github.com/tidwall/finn/logo.jpg -------------------------------------------------------------------------------- /vendor/github.com/tidwall/gjson/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/gjson/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/gjson/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidwall/summitdb/bc639291bb251f21b05c7e87526faa28f5f8ae23/vendor/github.com/tidwall/gjson/logo.png -------------------------------------------------------------------------------- /vendor/github.com/tidwall/grect/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/grect/README.md: -------------------------------------------------------------------------------- 1 | GRECT 2 | ==== 3 | 4 | Quickly get the outer rectangle for GeoJSON, WKT, WKB. 5 | 6 | ```go 7 | r := grect.Get(`{ 8 | "type": "Polygon", 9 | "coordinates": [ 10 | [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], 11 | [100.0, 1.0], [100.0, 0.0] ] 12 | ] 13 | }`) 14 | fmt.Printf("%v %v\n", r.Min, r.Max) 15 | // Output: 16 | // [100 0] [101 1] 17 | ``` 18 | 19 | ## Contact 20 | Josh Baker [@tidwall](http://twitter.com/tidwall) 21 | 22 | ## License 23 | 24 | GRECT source code is available under the MIT [License](/LICENSE). 25 | 26 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/less/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/less/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/match/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/match/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/match/README.md: -------------------------------------------------------------------------------- 1 | Match 2 | ===== 3 | Build Status 4 | GoDoc 5 | 6 | Match is a very simple pattern matcher where '*' matches on any 7 | number characters and '?' matches on any one character. 8 | Installing 9 | ---------- 10 | 11 | ``` 12 | go get -u github.com/tidwall/match 13 | ``` 14 | 15 | Example 16 | ------- 17 | 18 | ```go 19 | match.Match("hello", "*llo") 20 | match.Match("jello", "?ello") 21 | match.Match("hello", "h*o") 22 | ``` 23 | 24 | 25 | Contact 26 | ------- 27 | Josh Baker [@tidwall](http://twitter.com/tidwall) 28 | 29 | License 30 | ------- 31 | Redcon source code is available under the MIT [License](/LICENSE). 32 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/raft-boltdb/README.md: -------------------------------------------------------------------------------- 1 | raft-boltdb 2 | =========== 3 | 4 | This repository provides the `raftboltdb` package. The package exports the 5 | `BoltStore` which is an implementation of both a `LogStore` and `StableStore`. 6 | 7 | It is meant to be used as a backend for the `raft` [package 8 | here](https://github.com/hashicorp/raft). 9 | 10 | This implementation uses [BoltDB](https://github.com/boltdb/bolt). BoltDB is 11 | a simple key/value store implemented in pure Go, and inspired by LMDB. 12 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/raft-boltdb/bench_test.go: -------------------------------------------------------------------------------- 1 | package raftboltdb 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "github.com/hashicorp/raft/bench" 8 | ) 9 | 10 | func BenchmarkBoltStore_FirstIndex(b *testing.B) { 11 | store := testBoltStore(b) 12 | defer store.Close() 13 | defer os.Remove(store.path) 14 | 15 | raftbench.FirstIndex(b, store) 16 | } 17 | 18 | func BenchmarkBoltStore_LastIndex(b *testing.B) { 19 | store := testBoltStore(b) 20 | defer store.Close() 21 | defer os.Remove(store.path) 22 | 23 | raftbench.LastIndex(b, store) 24 | } 25 | 26 | func BenchmarkBoltStore_GetLog(b *testing.B) { 27 | store := testBoltStore(b) 28 | defer store.Close() 29 | defer os.Remove(store.path) 30 | 31 | raftbench.GetLog(b, store) 32 | } 33 | 34 | func BenchmarkBoltStore_StoreLog(b *testing.B) { 35 | store := testBoltStore(b) 36 | defer store.Close() 37 | defer os.Remove(store.path) 38 | 39 | raftbench.StoreLog(b, store) 40 | } 41 | 42 | func BenchmarkBoltStore_StoreLogs(b *testing.B) { 43 | store := testBoltStore(b) 44 | defer store.Close() 45 | defer os.Remove(store.path) 46 | 47 | raftbench.StoreLogs(b, store) 48 | } 49 | 50 | func BenchmarkBoltStore_DeleteRange(b *testing.B) { 51 | store := testBoltStore(b) 52 | defer store.Close() 53 | defer os.Remove(store.path) 54 | 55 | raftbench.DeleteRange(b, store) 56 | } 57 | 58 | func BenchmarkBoltStore_Set(b *testing.B) { 59 | store := testBoltStore(b) 60 | defer store.Close() 61 | defer os.Remove(store.path) 62 | 63 | raftbench.Set(b, store) 64 | } 65 | 66 | func BenchmarkBoltStore_Get(b *testing.B) { 67 | store := testBoltStore(b) 68 | defer store.Close() 69 | defer os.Remove(store.path) 70 | 71 | raftbench.Get(b, store) 72 | } 73 | 74 | func BenchmarkBoltStore_SetUint64(b *testing.B) { 75 | store := testBoltStore(b) 76 | defer store.Close() 77 | defer os.Remove(store.path) 78 | 79 | raftbench.SetUint64(b, store) 80 | } 81 | 82 | func BenchmarkBoltStore_GetUint64(b *testing.B) { 83 | store := testBoltStore(b) 84 | defer store.Close() 85 | defer os.Remove(store.path) 86 | 87 | raftbench.GetUint64(b, store) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/raft-boltdb/util.go: -------------------------------------------------------------------------------- 1 | package raftboltdb 2 | 3 | import ( 4 | "bytes" 5 | "encoding/binary" 6 | 7 | "github.com/hashicorp/go-msgpack/codec" 8 | ) 9 | 10 | // Decode reverses the encode operation on a byte slice input 11 | func decodeMsgPack(buf []byte, out interface{}) error { 12 | r := bytes.NewBuffer(buf) 13 | hd := codec.MsgpackHandle{} 14 | dec := codec.NewDecoder(r, &hd) 15 | return dec.Decode(out) 16 | } 17 | 18 | // Encode writes an encoded object to a new bytes buffer 19 | func encodeMsgPack(in interface{}) (*bytes.Buffer, error) { 20 | buf := bytes.NewBuffer(nil) 21 | hd := codec.MsgpackHandle{} 22 | enc := codec.NewEncoder(buf, &hd) 23 | err := enc.Encode(in) 24 | return buf, err 25 | } 26 | 27 | // Converts bytes to an integer 28 | func bytesToUint64(b []byte) uint64 { 29 | return binary.BigEndian.Uint64(b) 30 | } 31 | 32 | // Converts a uint to a byte slice 33 | func uint64ToBytes(u uint64) []byte { 34 | buf := make([]byte, 8) 35 | binary.BigEndian.PutUint64(buf, u) 36 | return buf 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/raft-fastlog/README.md: -------------------------------------------------------------------------------- 1 | raft-fastlog 2 | =========== 3 | 4 | This repository provides the `raftfastlog` package. 5 | The package exports a Raft Store which is an implementation of a 6 | `LogStore`, `StableStore`, and `PeerStore`. 7 | 8 | It is meant to be used as a backend for the `raft` 9 | [package here](https://github.com/hashicorp/raft). 10 | 11 | This implementation is an in-memory database that persists to disk. 12 | 13 | RaftStore Performance Comparison 14 | -------------------------------- 15 | 16 | FastLog (This implementation) 17 | ``` 18 | BenchmarkBuntStore_FirstIndex-8 20000000 92 ns/op 19 | BenchmarkBuntStore_LastIndex-8 20000000 92 ns/op 20 | BenchmarkBuntStore_GetLog-8 10000000 139 ns/op 21 | BenchmarkBuntStore_StoreLog-8 1000000 2028 ns/op 22 | BenchmarkBuntStore_StoreLogs-8 300000 4507 ns/op 23 | BenchmarkBuntStore_DeleteRange-8 1000000 3164 ns/op 24 | BenchmarkBuntStore_Set-8 1000000 1522 ns/op 25 | BenchmarkBuntStore_Get-8 10000000 119 ns/op 26 | BenchmarkBuntStore_SetUint64-8 1000000 1506 ns/op 27 | BenchmarkBuntStore_GetUint64-8 20000000 117 ns/op 28 | ``` 29 | 30 | [MDB](https://github.com/hashicorp/raft-mdb) 31 | ``` 32 | BenchmarkMDBStore_FirstIndex-8 500000 3043 ns/op 33 | BenchmarkMDBStore_LastIndex-8 500000 2941 ns/op 34 | BenchmarkMDBStore_GetLog-8 300000 4665 ns/op 35 | BenchmarkMDBStore_StoreLog-8 10000 183860 ns/op 36 | BenchmarkMDBStore_StoreLogs-8 10000 193783 ns/op 37 | BenchmarkMDBStore_DeleteRange-8 10000 199927 ns/op 38 | BenchmarkMDBStore_Set-8 10000 147540 ns/op 39 | BenchmarkMDBStore_Get-8 500000 2324 ns/op 40 | BenchmarkMDBStore_SetUint64-8 10000 162291 ns/op 41 | BenchmarkMDBStore_GetUint64-8 1000000 2451 ns/op 42 | ``` 43 | 44 | [BoltDB](https://github.com/hashicorp/raft-boltdb) 45 | ``` 46 | BenchmarkBoltStore_FirstIndex-8 2000000 848 ns/op 47 | BenchmarkBoltStore_LastIndex-8 2000000 857 ns/op 48 | BenchmarkBoltStore_GetLog-8 500000 3169 ns/op 49 | BenchmarkBoltStore_StoreLog-8 10000 197432 ns/op 50 | BenchmarkBoltStore_StoreLogs-8 10000 205238 ns/op 51 | BenchmarkBoltStore_DeleteRange-8 10000 189994 ns/op 52 | BenchmarkBoltStore_Set-8 10000 177010 ns/op 53 | BenchmarkBoltStore_Get-8 2000000 983 ns/op 54 | BenchmarkBoltStore_SetUint64-8 10000 175435 ns/op 55 | BenchmarkBoltStore_GetUint64-8 2000000 976 ns/op 56 | ``` 57 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/raft-redcon/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/raft-redcon/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/raft-redcon/README.md: -------------------------------------------------------------------------------- 1 | Raft-Redcon 2 | =========== 3 | Build Status 4 | GoDoc 5 | 6 | Raft-Redcon is a raft transport layer that implements the [Redis Protocol](http://redis.io/topics/protocol). 7 | It's intended to be used with [hashicorp/raft](https://github.com/hashicorp/raft). 8 | It utilizes [Redcon](https://github.com/tidwall/redcon) under the hood, 9 | and is a central component of the [Finn](https://github.com/tidwall/finn) project. 10 | 11 | Contact 12 | ------- 13 | Josh Baker [@tidwall](http://twitter.com/tidwall) 14 | 15 | License 16 | ------- 17 | Raft-Redcon source code is available under the MIT [License](/LICENSE). 18 | 19 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/redcon/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/redcon/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/redcon/example/clone.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "strings" 6 | "sync" 7 | 8 | "github.com/tidwall/redcon" 9 | ) 10 | 11 | var addr = ":6380" 12 | 13 | func main() { 14 | var mu sync.RWMutex 15 | var items = make(map[string][]byte) 16 | go log.Printf("started server at %s", addr) 17 | err := redcon.ListenAndServe(addr, 18 | func(conn redcon.Conn, cmd redcon.Command) { 19 | switch strings.ToLower(string(cmd.Args[0])) { 20 | default: 21 | conn.WriteError("ERR unknown command '" + string(cmd.Args[0]) + "'") 22 | case "detach": 23 | hconn := conn.Detach() 24 | log.Printf("connection has been detached") 25 | go func() { 26 | defer hconn.Close() 27 | hconn.WriteString("OK") 28 | hconn.Flush() 29 | }() 30 | return 31 | case "ping": 32 | conn.WriteString("PONG") 33 | case "quit": 34 | conn.WriteString("OK") 35 | conn.Close() 36 | case "set": 37 | if len(cmd.Args) != 3 { 38 | conn.WriteError("ERR wrong number of arguments for '" + string(cmd.Args[0]) + "' command") 39 | return 40 | } 41 | mu.Lock() 42 | items[string(cmd.Args[1])] = cmd.Args[2] 43 | mu.Unlock() 44 | conn.WriteString("OK") 45 | case "get": 46 | if len(cmd.Args) != 2 { 47 | conn.WriteError("ERR wrong number of arguments for '" + string(cmd.Args[0]) + "' command") 48 | return 49 | } 50 | mu.RLock() 51 | val, ok := items[string(cmd.Args[1])] 52 | mu.RUnlock() 53 | if !ok { 54 | conn.WriteNull() 55 | } else { 56 | conn.WriteBulk(val) 57 | } 58 | case "del": 59 | if len(cmd.Args) != 2 { 60 | conn.WriteError("ERR wrong number of arguments for '" + string(cmd.Args[0]) + "' command") 61 | return 62 | } 63 | mu.Lock() 64 | _, ok := items[string(cmd.Args[1])] 65 | delete(items, string(cmd.Args[1])) 66 | mu.Unlock() 67 | if !ok { 68 | conn.WriteInt(0) 69 | } else { 70 | conn.WriteInt(1) 71 | } 72 | } 73 | }, 74 | func(conn redcon.Conn) bool { 75 | // use this function to accept or deny the connection. 76 | // log.Printf("accept: %s", conn.RemoteAddr()) 77 | return true 78 | }, 79 | func(conn redcon.Conn, err error) { 80 | // this is called when the connection has been closed 81 | // log.Printf("closed: %s, err: %v", conn.RemoteAddr(), err) 82 | }, 83 | ) 84 | if err != nil { 85 | log.Fatal(err) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/redcon/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidwall/summitdb/bc639291bb251f21b05c7e87526faa28f5f8ae23/vendor/github.com/tidwall/redcon/logo.png -------------------------------------------------------------------------------- /vendor/github.com/tidwall/redlog/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/redlog/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/redlog/README.md: -------------------------------------------------------------------------------- 1 | Redlog 2 | ====== 3 | Build Status 4 | GoDoc 5 | 6 | Redlog is a [Redis style logger](http://build47.com/redis-log-format-levels/) for Go. 7 | 8 | Installing 9 | ---------- 10 | 11 | ``` 12 | go get -u github.com/tidwall/redlog 13 | ``` 14 | 15 | Example 16 | ------- 17 | 18 | ```go 19 | log := redlog.New(os.Stderr) 20 | log.Printf("Server started at 10.0.1.5:6379") 21 | log.Debugf("Connected to leader") 22 | log.Warningf("Heartbeat timeout reached, starting election") 23 | ``` 24 | 25 | Output: 26 | 27 | ``` 28 | [93324:M] 29 Aug 09:30:59.943 * Server started at 10.0.1.5:6379 29 | [93324:M] 29 Aug 09:31:01.892 . Connected to leader 30 | [93324:M] 29 Aug 09:31:02.331 # Heartbeat timeout reached, starting election 31 | ``` 32 | 33 | Contact 34 | ------- 35 | Josh Baker [@tidwall](http://twitter.com/tidwall) 36 | 37 | License 38 | ------- 39 | Redcon source code is available under the MIT [License](/LICENSE). 40 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/redlog/redlog_test.go: -------------------------------------------------------------------------------- 1 | package redlog 2 | 3 | import ( 4 | "bytes" 5 | "testing" 6 | ) 7 | 8 | func TestLog(t *testing.T) { 9 | buf := &bytes.Buffer{} 10 | l := New(buf) 11 | l.Printf("hello world\n") 12 | } 13 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/rtree/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.6 4 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/rtree/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Josh Baker 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/rtree/README.md: -------------------------------------------------------------------------------- 1 | RTree implementation for Go 2 | =========================== 3 | 4 | [![Build Status](https://travis-ci.org/tidwall/rtree.svg?branch=master)](https://travis-ci.org/tidwall/rtree) 5 | [![GoDoc](https://godoc.org/github.com/tidwall/rtree?status.svg)](https://godoc.org/github.com/tidwall/rtree) 6 | 7 | This package provides an in-memory R-Tree implementation for Go, useful as a spatial data structure. 8 | It has support for 1-20 dimensions, and can store and search multidimensions interchangably in the same tree. 9 | 10 | Authors 11 | ------- 12 | * 1983 Original algorithm and test code by Antonin Guttman and Michael Stonebraker, UC Berkely 13 | * 1994 ANCI C ported from original test code by Melinda Green 14 | * 1995 Sphere volume fix for degeneracy problem submitted by Paul Brook 15 | * 2004 Templated C++ port by Greg Douglas 16 | * 2016 Go port by Josh Baker 17 | 18 | License 19 | ------- 20 | RTree source code is available under the MIT License. 21 | 22 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/rtree/gen/gen.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "io/ioutil" 6 | "log" 7 | "os" 8 | "strconv" 9 | "strings" 10 | ) 11 | 12 | func main() { 13 | var dims int 14 | var debug bool 15 | flag.IntVar(&dims, "dims", 4, "number of dimensions") 16 | flag.BoolVar(&debug, "debug", false, "turn on debug tracing") 17 | flag.Parse() 18 | // process rtree.go 19 | data, err := ioutil.ReadFile("src/rtree.go") 20 | if err != nil { 21 | log.Fatal(err) 22 | } 23 | data = []byte(strings.Replace(string(data), "// +build ignore", "// generated; DO NOT EDIT!", -1)) 24 | if debug { 25 | data = []byte(strings.Replace(string(data), "TDEBUG", "true", -1)) 26 | } else { 27 | data = []byte(strings.Replace(string(data), "TDEBUG", "false", -1)) 28 | } 29 | var dimouts = make([]string, dims) 30 | var output string 31 | var recording bool 32 | lines := strings.Split(string(data), "\n") 33 | for _, line := range lines { 34 | if strings.HasPrefix(strings.TrimSpace(line), "//") { 35 | idx := strings.Index(line, "//") 36 | switch strings.ToUpper(strings.TrimSpace(line[idx+2:])) { 37 | case "BEGIN": 38 | recording = true 39 | for i := 0; i < len(dimouts); i++ { 40 | dimouts[i] = "" 41 | } 42 | continue 43 | case "END": 44 | for _, out := range dimouts { 45 | if out != "" { 46 | output += out 47 | } 48 | } 49 | recording = false 50 | continue 51 | } 52 | } 53 | if recording { 54 | for i := 0; i < len(dimouts); i++ { 55 | dimouts[i] += strings.Replace(line, "TNUMDIMS", strconv.FormatInt(int64(i+1), 10), -1) + "\n" 56 | } 57 | } else { 58 | output += line + "\n" 59 | } 60 | } 61 | // process rtree_base.go 62 | if err := os.RemoveAll("../dims"); err != nil { 63 | log.Fatal(err) 64 | } 65 | for i := 0; i < dims; i++ { 66 | sdim := strconv.FormatInt(int64(i+1), 10) 67 | data, err := ioutil.ReadFile("src/rtree_base.go") 68 | if err != nil { 69 | log.Fatal(err) 70 | } 71 | data = []byte(strings.Split(string(data), "// FILE_START")[1]) 72 | if debug { 73 | data = []byte(strings.Replace(string(data), "TDEBUG", "true", -1)) 74 | } else { 75 | data = []byte(strings.Replace(string(data), "TDEBUG", "false", -1)) 76 | } 77 | data = []byte(strings.Replace(string(data), "TNUMDIMS", strconv.FormatInt(int64(i+1), 10), -1)) 78 | data = []byte(strings.Replace(string(data), "DD_", "d"+strconv.FormatInt(int64(i+1), 10), -1)) 79 | if err := os.MkdirAll("../dims/d"+sdim, 0777); err != nil { 80 | log.Fatal(err) 81 | } 82 | output = string(append([]byte(output), data...)) 83 | } 84 | if err := ioutil.WriteFile("../rtree.go", []byte(output), 0666); err != nil { 85 | log.Fatal(err) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/rtree/gen/gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | cd $(dirname "${BASH_SOURCE[0]}") 6 | 7 | go run gen.go --dims=20 --debug=false 8 | cd .. 9 | go fmt 10 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/sjson/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/sjson/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /vendor/github.com/tidwall/sjson/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidwall/summitdb/bc639291bb251f21b05c7e87526faa28f5f8ae23/vendor/github.com/tidwall/sjson/logo.png -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_bsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd netbsd openbsd 6 | 7 | package terminal 8 | 9 | import "syscall" 10 | 11 | const ioctlReadTermios = syscall.TIOCGETA 12 | const ioctlWriteTermios = syscall.TIOCSETA 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package terminal 6 | 7 | // These constants are declared here, rather than importing 8 | // them from the syscall package as some syscall packages, even 9 | // on linux, for example gccgo, do not declare them. 10 | const ioctlReadTermios = 0x5401 // syscall.TCGETS 11 | const ioctlWriteTermios = 0x5402 // syscall.TCSETS 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_plan9.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package terminal provides support functions for dealing with terminals, as 6 | // commonly found on UNIX systems. 7 | // 8 | // Putting a terminal into raw mode is the most common requirement: 9 | // 10 | // oldState, err := terminal.MakeRaw(0) 11 | // if err != nil { 12 | // panic(err) 13 | // } 14 | // defer terminal.Restore(0, oldState) 15 | package terminal 16 | 17 | import ( 18 | "fmt" 19 | "runtime" 20 | ) 21 | 22 | type State struct{} 23 | 24 | // IsTerminal returns true if the given file descriptor is a terminal. 25 | func IsTerminal(fd int) bool { 26 | return false 27 | } 28 | 29 | // MakeRaw put the terminal connected to the given file descriptor into raw 30 | // mode and returns the previous state of the terminal so that it can be 31 | // restored. 32 | func MakeRaw(fd int) (*State, error) { 33 | return nil, fmt.Errorf("terminal: MakeRaw not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 34 | } 35 | 36 | // GetState returns the current state of a terminal which may be useful to 37 | // restore the terminal after a signal. 38 | func GetState(fd int) (*State, error) { 39 | return nil, fmt.Errorf("terminal: GetState not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 40 | } 41 | 42 | // Restore restores the terminal connected to the given file descriptor to a 43 | // previous state. 44 | func Restore(fd int, state *State) error { 45 | return fmt.Errorf("terminal: Restore not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 46 | } 47 | 48 | // GetSize returns the dimensions of the given terminal. 49 | func GetSize(fd int) (width, height int, err error) { 50 | return 0, 0, fmt.Errorf("terminal: GetSize not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 51 | } 52 | 53 | // ReadPassword reads a line of input from a terminal without local echo. This 54 | // is commonly used for inputting passwords and other sensitive data. The slice 55 | // returned does not include the \n. 56 | func ReadPassword(fd int) ([]byte, error) { 57 | return nil, fmt.Errorf("terminal: ReadPassword not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_solaris.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build solaris 6 | 7 | package terminal // import "golang.org/x/crypto/ssh/terminal" 8 | 9 | import ( 10 | "golang.org/x/sys/unix" 11 | "io" 12 | "syscall" 13 | ) 14 | 15 | // State contains the state of a terminal. 16 | type State struct { 17 | termios syscall.Termios 18 | } 19 | 20 | // IsTerminal returns true if the given file descriptor is a terminal. 21 | func IsTerminal(fd int) bool { 22 | // see: http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libbc/libc/gen/common/isatty.c 23 | var termio unix.Termio 24 | err := unix.IoctlSetTermio(fd, unix.TCGETA, &termio) 25 | return err == nil 26 | } 27 | 28 | // ReadPassword reads a line of input from a terminal without local echo. This 29 | // is commonly used for inputting passwords and other sensitive data. The slice 30 | // returned does not include the \n. 31 | func ReadPassword(fd int) ([]byte, error) { 32 | // see also: http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libast/common/uwin/getpass.c 33 | val, err := unix.IoctlGetTermios(fd, unix.TCGETS) 34 | if err != nil { 35 | return nil, err 36 | } 37 | oldState := *val 38 | 39 | newState := oldState 40 | newState.Lflag &^= syscall.ECHO 41 | newState.Lflag |= syscall.ICANON | syscall.ISIG 42 | newState.Iflag |= syscall.ICRNL 43 | err = unix.IoctlSetTermios(fd, unix.TCSETS, &newState) 44 | if err != nil { 45 | return nil, err 46 | } 47 | 48 | defer unix.IoctlSetTermios(fd, unix.TCSETS, &oldState) 49 | 50 | var buf [16]byte 51 | var ret []byte 52 | for { 53 | n, err := syscall.Read(fd, buf[:]) 54 | if err != nil { 55 | return nil, err 56 | } 57 | if n == 0 { 58 | if len(ret) == 0 { 59 | return nil, io.EOF 60 | } 61 | break 62 | } 63 | if buf[n-1] == '\n' { 64 | n-- 65 | } 66 | ret = append(ret, buf[:n]...) 67 | if n < len(buf) { 68 | break 69 | } 70 | } 71 | 72 | return ret, nil 73 | } 74 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/collate/build/table.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package build 6 | 7 | import ( 8 | "fmt" 9 | "io" 10 | "reflect" 11 | 12 | "golang.org/x/text/internal/colltab" 13 | ) 14 | 15 | // table is an intermediate structure that roughly resembles the table in collate. 16 | type table struct { 17 | colltab.Table 18 | trie trie 19 | root *trieHandle 20 | } 21 | 22 | // print writes the table as Go compilable code to w. It prefixes the 23 | // variable names with name. It returns the number of bytes written 24 | // and the size of the resulting table. 25 | func (t *table) fprint(w io.Writer, name string) (n, size int, err error) { 26 | update := func(nn, sz int, e error) { 27 | n += nn 28 | if err == nil { 29 | err = e 30 | } 31 | size += sz 32 | } 33 | // Write arrays needed for the structure. 34 | update(printColElems(w, t.ExpandElem, name+"ExpandElem")) 35 | update(printColElems(w, t.ContractElem, name+"ContractElem")) 36 | update(t.trie.printArrays(w, name)) 37 | update(printArray(t.ContractTries, w, name)) 38 | 39 | nn, e := fmt.Fprintf(w, "// Total size of %sTable is %d bytes\n", name, size) 40 | update(nn, 0, e) 41 | return 42 | } 43 | 44 | func (t *table) fprintIndex(w io.Writer, h *trieHandle, id string) (n int, err error) { 45 | p := func(f string, a ...interface{}) { 46 | nn, e := fmt.Fprintf(w, f, a...) 47 | n += nn 48 | if err == nil { 49 | err = e 50 | } 51 | } 52 | p("\t{ // %s\n", id) 53 | p("\t\tlookupOffset: 0x%x,\n", h.lookupStart) 54 | p("\t\tvaluesOffset: 0x%x,\n", h.valueStart) 55 | p("\t},\n") 56 | return 57 | } 58 | 59 | func printColElems(w io.Writer, a []uint32, name string) (n, sz int, err error) { 60 | p := func(f string, a ...interface{}) { 61 | nn, e := fmt.Fprintf(w, f, a...) 62 | n += nn 63 | if err == nil { 64 | err = e 65 | } 66 | } 67 | sz = len(a) * int(reflect.TypeOf(uint32(0)).Size()) 68 | p("// %s: %d entries, %d bytes\n", name, len(a), sz) 69 | p("var %s = [%d]uint32 {", name, len(a)) 70 | for i, c := range a { 71 | switch { 72 | case i%64 == 0: 73 | p("\n\t// Block %d, offset 0x%x\n", i/64, i) 74 | case (i%64)%6 == 0: 75 | p("\n\t") 76 | } 77 | p("0x%.8X, ", c) 78 | } 79 | p("\n}\n\n") 80 | return 81 | } 82 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/collate/export_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package collate 6 | 7 | // Export for testing. 8 | // TODO: no longer necessary. Remove at some point. 9 | 10 | import ( 11 | "fmt" 12 | 13 | "golang.org/x/text/internal/colltab" 14 | ) 15 | 16 | const ( 17 | defaultSecondary = 0x20 18 | defaultTertiary = 0x2 19 | ) 20 | 21 | type Weights struct { 22 | Primary, Secondary, Tertiary, Quaternary int 23 | } 24 | 25 | func W(ce ...int) Weights { 26 | w := Weights{ce[0], defaultSecondary, defaultTertiary, 0} 27 | if len(ce) > 1 { 28 | w.Secondary = ce[1] 29 | } 30 | if len(ce) > 2 { 31 | w.Tertiary = ce[2] 32 | } 33 | if len(ce) > 3 { 34 | w.Quaternary = ce[3] 35 | } 36 | return w 37 | } 38 | func (w Weights) String() string { 39 | return fmt.Sprintf("[%X.%X.%X.%X]", w.Primary, w.Secondary, w.Tertiary, w.Quaternary) 40 | } 41 | 42 | func convertFromWeights(ws []Weights) []colltab.Elem { 43 | out := make([]colltab.Elem, len(ws)) 44 | for i, w := range ws { 45 | out[i], _ = colltab.MakeElem(w.Primary, w.Secondary, w.Tertiary, 0) 46 | if out[i] == colltab.Ignore && w.Quaternary > 0 { 47 | out[i] = colltab.MakeQuaternary(w.Quaternary) 48 | } 49 | } 50 | return out 51 | } 52 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/collate/index.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package collate 6 | 7 | import "golang.org/x/text/internal/colltab" 8 | 9 | const blockSize = 64 10 | 11 | func getTable(t tableIndex) *colltab.Table { 12 | return &colltab.Table{ 13 | Index: colltab.Trie{ 14 | Index0: mainLookup[:][blockSize*t.lookupOffset:], 15 | Values0: mainValues[:][blockSize*t.valuesOffset:], 16 | Index: mainLookup[:], 17 | Values: mainValues[:], 18 | }, 19 | ExpandElem: mainExpandElem[:], 20 | ContractTries: colltab.ContractTrieSet(mainCTEntries[:]), 21 | ContractElem: mainContractElem[:], 22 | MaxContractLen: 18, 23 | VariableTop: varTop, 24 | } 25 | } 26 | 27 | // tableIndex holds information for constructing a table 28 | // for a certain locale based on the main table. 29 | type tableIndex struct { 30 | lookupOffset uint32 31 | valuesOffset uint32 32 | } 33 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/collate/sort.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package collate 6 | 7 | import ( 8 | "bytes" 9 | "sort" 10 | ) 11 | 12 | const ( 13 | maxSortBuffer = 40960 14 | maxSortEntries = 4096 15 | ) 16 | 17 | type swapper interface { 18 | Swap(i, j int) 19 | } 20 | 21 | type sorter struct { 22 | buf *Buffer 23 | keys [][]byte 24 | src swapper 25 | } 26 | 27 | func (s *sorter) init(n int) { 28 | if s.buf == nil { 29 | s.buf = &Buffer{} 30 | s.buf.init() 31 | } 32 | if cap(s.keys) < n { 33 | s.keys = make([][]byte, n) 34 | } 35 | s.keys = s.keys[0:n] 36 | } 37 | 38 | func (s *sorter) sort(src swapper) { 39 | s.src = src 40 | sort.Sort(s) 41 | } 42 | 43 | func (s sorter) Len() int { 44 | return len(s.keys) 45 | } 46 | 47 | func (s sorter) Less(i, j int) bool { 48 | return bytes.Compare(s.keys[i], s.keys[j]) == -1 49 | } 50 | 51 | func (s sorter) Swap(i, j int) { 52 | s.keys[i], s.keys[j] = s.keys[j], s.keys[i] 53 | s.src.Swap(i, j) 54 | } 55 | 56 | // A Lister can be sorted by Collator's Sort method. 57 | type Lister interface { 58 | Len() int 59 | Swap(i, j int) 60 | // Bytes returns the bytes of the text at index i. 61 | Bytes(i int) []byte 62 | } 63 | 64 | // Sort uses sort.Sort to sort the strings represented by x using the rules of c. 65 | func (c *Collator) Sort(x Lister) { 66 | n := x.Len() 67 | c.sorter.init(n) 68 | for i := 0; i < n; i++ { 69 | c.sorter.keys[i] = c.Key(c.sorter.buf, x.Bytes(i)) 70 | } 71 | c.sorter.sort(x) 72 | } 73 | 74 | // SortStrings uses sort.Sort to sort the strings in x using the rules of c. 75 | func (c *Collator) SortStrings(x []string) { 76 | c.sorter.init(len(x)) 77 | for i, s := range x { 78 | c.sorter.keys[i] = c.KeyFromString(c.sorter.buf, s) 79 | } 80 | c.sorter.sort(sort.StringSlice(x)) 81 | } 82 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/collate/sort_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package collate_test 6 | 7 | import ( 8 | "fmt" 9 | "testing" 10 | 11 | "golang.org/x/text/collate" 12 | "golang.org/x/text/language" 13 | ) 14 | 15 | func ExampleCollator_Strings() { 16 | c := collate.New(language.Und) 17 | strings := []string{ 18 | "ad", 19 | "ab", 20 | "äb", 21 | "ac", 22 | } 23 | c.SortStrings(strings) 24 | fmt.Println(strings) 25 | // Output: [ab äb ac ad] 26 | } 27 | 28 | type sorter []string 29 | 30 | func (s sorter) Len() int { 31 | return len(s) 32 | } 33 | 34 | func (s sorter) Swap(i, j int) { 35 | s[j], s[i] = s[i], s[j] 36 | } 37 | 38 | func (s sorter) Bytes(i int) []byte { 39 | return []byte(s[i]) 40 | } 41 | 42 | func TestSort(t *testing.T) { 43 | c := collate.New(language.English) 44 | strings := []string{ 45 | "bcd", 46 | "abc", 47 | "ddd", 48 | } 49 | c.Sort(sorter(strings)) 50 | res := fmt.Sprint(strings) 51 | want := "[abc bcd ddd]" 52 | if res != want { 53 | t.Errorf("found %s; want %s", res, want) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/collate/tools/colcmp/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2012 The Go Authors. All rights reserved. 2 | # Use of this source code is governed by a BSD-style 3 | # license that can be found in the LICENSE file. 4 | 5 | chars: 6 | go run ../../maketables.go -tables=chars -package=main > chars.go 7 | gofmt -w -s chars.go 8 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/collate/tools/colcmp/col.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "log" 9 | "unicode/utf16" 10 | 11 | "golang.org/x/text/collate" 12 | "golang.org/x/text/language" 13 | ) 14 | 15 | // Input holds an input string in both UTF-8 and UTF-16 format. 16 | type Input struct { 17 | index int // used for restoring to original random order 18 | UTF8 []byte 19 | UTF16 []uint16 20 | key []byte // used for sorting 21 | } 22 | 23 | func (i Input) String() string { 24 | return string(i.UTF8) 25 | } 26 | 27 | func makeInput(s8 []byte, s16 []uint16) Input { 28 | return Input{UTF8: s8, UTF16: s16} 29 | } 30 | 31 | func makeInputString(s string) Input { 32 | return Input{ 33 | UTF8: []byte(s), 34 | UTF16: utf16.Encode([]rune(s)), 35 | } 36 | } 37 | 38 | // Collator is an interface for architecture-specific implementations of collation. 39 | type Collator interface { 40 | // Key generates a sort key for the given input. Implemenations 41 | // may return nil if a collator does not support sort keys. 42 | Key(s Input) []byte 43 | 44 | // Compare returns -1 if a < b, 1 if a > b and 0 if a == b. 45 | Compare(a, b Input) int 46 | } 47 | 48 | // CollatorFactory creates a Collator for a given language tag. 49 | type CollatorFactory struct { 50 | name string 51 | makeFn func(tag string) (Collator, error) 52 | description string 53 | } 54 | 55 | var collators = []CollatorFactory{} 56 | 57 | // AddFactory registers f as a factory for an implementation of Collator. 58 | func AddFactory(f CollatorFactory) { 59 | collators = append(collators, f) 60 | } 61 | 62 | func getCollator(name, locale string) Collator { 63 | for _, f := range collators { 64 | if f.name == name { 65 | col, err := f.makeFn(locale) 66 | if err != nil { 67 | log.Fatal(err) 68 | } 69 | return col 70 | } 71 | } 72 | log.Fatalf("collator of type %q not found", name) 73 | return nil 74 | } 75 | 76 | // goCollator is an implemention of Collator using go's own collator. 77 | type goCollator struct { 78 | c *collate.Collator 79 | buf collate.Buffer 80 | } 81 | 82 | func init() { 83 | AddFactory(CollatorFactory{"go", newGoCollator, "Go's native collator implementation."}) 84 | } 85 | 86 | func newGoCollator(loc string) (Collator, error) { 87 | c := &goCollator{c: collate.New(language.Make(loc))} 88 | return c, nil 89 | } 90 | 91 | func (c *goCollator) Key(b Input) []byte { 92 | return c.c.Key(&c.buf, b.UTF8) 93 | } 94 | 95 | func (c *goCollator) Compare(a, b Input) int { 96 | return c.c.Compare(a.UTF8, b.UTF8) 97 | } 98 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/internal/colltab/colltab_test.go: -------------------------------------------------------------------------------- 1 | package colltab 2 | 3 | import ( 4 | "testing" 5 | 6 | "golang.org/x/text/language" 7 | ) 8 | 9 | func TestMatchLang(t *testing.T) { 10 | tags := []language.Tag{ 11 | 0: language.Und, 12 | 1: language.MustParse("bs"), 13 | 2: language.German, 14 | 3: language.English, 15 | 4: language.AmericanEnglish, 16 | 5: language.MustParse("en-US-u-va-posix"), 17 | 6: language.Portuguese, 18 | 7: language.Serbian, 19 | 8: language.MustParse("sr-Latn"), 20 | 9: language.Chinese, 21 | 10: language.MustParse("zh-u-co-stroke"), 22 | 11: language.MustParse("zh-Hant-u-co-pinyin"), 23 | 12: language.TraditionalChinese, 24 | } 25 | for i, tc := range []struct { 26 | x int 27 | t language.Tag 28 | }{ 29 | {0, language.Und}, 30 | {0, language.Persian}, // Default to first element when no match. 31 | {3, language.English}, 32 | {4, language.AmericanEnglish}, 33 | {5, language.MustParse("en-US-u-va-posix")}, // Ext. variant match. 34 | {4, language.MustParse("en-US-u-va-noposix")}, // Ext. variant mismatch. 35 | {3, language.MustParse("en-UK-u-va-noposix")}, // Ext. variant mismatch. 36 | {7, language.Serbian}, 37 | {0, language.Croatian}, // Don't match to close language! 38 | {0, language.MustParse("gsw")}, // Don't match to close language! 39 | {1, language.MustParse("bs-Cyrl")}, // Odd, but correct. 40 | {1, language.MustParse("bs-Latn")}, // Estimated script drops. 41 | {8, language.MustParse("sr-Latn")}, 42 | {9, language.Chinese}, 43 | {9, language.SimplifiedChinese}, 44 | {12, language.TraditionalChinese}, 45 | {11, language.MustParse("zh-Hant-u-co-pinyin")}, 46 | // TODO: should this be 12? Either inherited value (10) or default is 47 | // fine in this case, though. Other locales are not affected. 48 | {10, language.MustParse("zh-Hant-u-co-stroke")}, 49 | // There is no "phonebk" sorting order for zh-Hant, so use default. 50 | {12, language.MustParse("zh-Hant-u-co-phonebk")}, 51 | {10, language.MustParse("zh-u-co-stroke")}, 52 | {12, language.MustParse("und-TW")}, // Infer script and language. 53 | {12, language.MustParse("und-HK")}, // Infer script and language. 54 | {6, language.MustParse("und-BR")}, // Infer script and language. 55 | {6, language.MustParse("und-PT")}, // Infer script and language. 56 | {2, language.MustParse("und-Latn-DE")}, // Infer language. 57 | {0, language.MustParse("und-Jpan-BR")}, // Infers "ja", so no match. 58 | {0, language.MustParse("zu")}, // No match past index. 59 | } { 60 | if x := MatchLang(tc.t, tags); x != tc.x { 61 | t.Errorf("%d: MatchLang(%q, tags) = %d; want %d", i, tc.t, x, tc.x) 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/internal/colltab/iter_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package colltab 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | func TestDoNorm(t *testing.T) { 12 | const div = -1 // The insertion point of the next block. 13 | tests := []struct { 14 | in, out []int 15 | }{{ 16 | in: []int{4, div, 3}, 17 | out: []int{3, 4}, 18 | }, { 19 | in: []int{4, div, 3, 3, 3}, 20 | out: []int{3, 3, 3, 4}, 21 | }, { 22 | in: []int{0, 4, div, 3}, 23 | out: []int{0, 3, 4}, 24 | }, { 25 | in: []int{0, 0, 4, 5, div, 3, 3}, 26 | out: []int{0, 0, 3, 3, 4, 5}, 27 | }, { 28 | in: []int{0, 0, 1, 4, 5, div, 3, 3}, 29 | out: []int{0, 0, 1, 3, 3, 4, 5}, 30 | }, { 31 | in: []int{0, 0, 1, 4, 5, div, 4, 4}, 32 | out: []int{0, 0, 1, 4, 4, 4, 5}, 33 | }, 34 | } 35 | for j, tt := range tests { 36 | i := Iter{} 37 | var w, p int 38 | for k, cc := range tt.in { 39 | 40 | if cc == div { 41 | w = 100 42 | p = k 43 | continue 44 | } 45 | i.Elems = append(i.Elems, makeCE([]int{w, defaultSecondary, 2, cc})) 46 | } 47 | i.doNorm(p, i.Elems[p].CCC()) 48 | if len(i.Elems) != len(tt.out) { 49 | t.Errorf("%d: length was %d; want %d", j, len(i.Elems), len(tt.out)) 50 | } 51 | prevCCC := uint8(0) 52 | for k, ce := range i.Elems { 53 | if int(ce.CCC()) != tt.out[k] { 54 | t.Errorf("%d:%d: unexpected CCC. Was %d; want %d", j, k, ce.CCC(), tt.out[k]) 55 | } 56 | if k > 0 && ce.CCC() == prevCCC && i.Elems[k-1].Primary() > ce.Primary() { 57 | t.Errorf("%d:%d: normalization crossed across CCC boundary.", j, k) 58 | } 59 | } 60 | } 61 | 62 | // Combining rune overflow is tested in search/pattern_test.go. 63 | } 64 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/internal/colltab/weighter.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package colltab // import "golang.org/x/text/internal/colltab" 6 | 7 | // A Weighter can be used as a source for Collator and Searcher. 8 | type Weighter interface { 9 | // Start finds the start of the segment that includes position p. 10 | Start(p int, b []byte) int 11 | 12 | // StartString finds the start of the segment that includes position p. 13 | StartString(p int, s string) int 14 | 15 | // AppendNext appends Elems to buf corresponding to the longest match 16 | // of a single character or contraction from the start of s. 17 | // It returns the new buf and the number of bytes consumed. 18 | AppendNext(buf []Elem, s []byte) (ce []Elem, n int) 19 | 20 | // AppendNextString appends Elems to buf corresponding to the longest match 21 | // of a single character or contraction from the start of s. 22 | // It returns the new buf and the number of bytes consumed. 23 | AppendNextString(buf []Elem, s string) (ce []Elem, n int) 24 | 25 | // Domain returns a slice of all single characters and contractions for which 26 | // collation elements are defined in this table. 27 | Domain() []string 28 | 29 | // Top returns the highest variable primary value. 30 | Top() uint32 31 | } 32 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/internal/colltab/weighter_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package colltab 6 | 7 | // testWeighter is a simple Weighter that returns weights from a user-defined map. 8 | type testWeighter map[string][]Elem 9 | 10 | func (t testWeighter) Start(int, []byte) int { return 0 } 11 | func (t testWeighter) StartString(int, string) int { return 0 } 12 | func (t testWeighter) Domain() []string { return nil } 13 | func (t testWeighter) Top() uint32 { return 0 } 14 | 15 | // maxContractBytes is the maximum length of any key in the map. 16 | const maxContractBytes = 10 17 | 18 | func (t testWeighter) AppendNext(buf []Elem, s []byte) ([]Elem, int) { 19 | n := len(s) 20 | if n > maxContractBytes { 21 | n = maxContractBytes 22 | } 23 | for i := n; i > 0; i-- { 24 | if e, ok := t[string(s[:i])]; ok { 25 | return append(buf, e...), i 26 | } 27 | } 28 | panic("incomplete testWeighter: could not find " + string(s)) 29 | } 30 | 31 | func (t testWeighter) AppendNextString(buf []Elem, s string) ([]Elem, int) { 32 | n := len(s) 33 | if n > maxContractBytes { 34 | n = maxContractBytes 35 | } 36 | for i := n; i > 0; i-- { 37 | if e, ok := t[s[:i]]; ok { 38 | return append(buf, e...), i 39 | } 40 | } 41 | panic("incomplete testWeighter: could not find " + s) 42 | } 43 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/internal/tag/tag_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package tag 6 | 7 | import ( 8 | "strings" 9 | "testing" 10 | ) 11 | 12 | var strdata = []string{ 13 | "aa ", 14 | "aaa ", 15 | "aaaa", 16 | "aaab", 17 | "aab ", 18 | "ab ", 19 | "ba ", 20 | "xxxx", 21 | "\xff\xff\xff\xff", 22 | } 23 | 24 | var testCases = map[string]int{ 25 | "a": 0, 26 | "aa": 0, 27 | "aaa": 1, 28 | "aa ": 0, 29 | "aaaa": 2, 30 | "aaab": 3, 31 | "b": 6, 32 | "ba": 6, 33 | " ": -1, 34 | "aaax": -1, 35 | "bbbb": -1, 36 | "zzzz": -1, 37 | } 38 | 39 | func TestIndex(t *testing.T) { 40 | index := Index(strings.Join(strdata, "")) 41 | for k, v := range testCases { 42 | if i := index.Index([]byte(k)); i != v { 43 | t.Errorf("%s: got %d; want %d", k, i, v) 44 | } 45 | } 46 | } 47 | 48 | func TestFixCase(t *testing.T) { 49 | tests := []string{ 50 | "aaaa", "AbCD", "abcd", 51 | "Zzzz", "AbCD", "Abcd", 52 | "Zzzz", "AbC", "", 53 | "XXX", "ab ", "", 54 | "XXX", "usd", "USD", 55 | "cmn", "AB ", "", 56 | "gsw", "CMN", "cmn", 57 | } 58 | for tc := tests; len(tc) > 0; tc = tc[3:] { 59 | b := []byte(tc[1]) 60 | if !FixCase(tc[0], b) { 61 | b = nil 62 | } 63 | if string(b) != tc[2] { 64 | t.Errorf("FixCase(%q, %q) = %q; want %q", tc[0], tc[1], b, tc[2]) 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/language/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2013 The Go Authors. All rights reserved. 2 | # Use of this source code is governed by a BSD-style 3 | # license that can be found in the LICENSE file. 4 | 5 | CLEANFILES+=maketables 6 | 7 | maketables: maketables.go 8 | go build $^ 9 | 10 | tables: maketables 11 | ./maketables > tables.go 12 | gofmt -w -s tables.go 13 | 14 | # Build (but do not run) maketables during testing, 15 | # just to make sure it still compiles. 16 | testshort: maketables 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/language/common.go: -------------------------------------------------------------------------------- 1 | // This file was generated by go generate; DO NOT EDIT 2 | 3 | package language 4 | 5 | // This file contains code common to the maketables.go and the package code. 6 | 7 | // langAliasType is the type of an alias in langAliasMap. 8 | type langAliasType int8 9 | 10 | const ( 11 | langDeprecated langAliasType = iota 12 | langMacro 13 | langLegacy 14 | 15 | langAliasTypeUnknown langAliasType = -1 16 | ) 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/language/display/dict_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package display 6 | 7 | import ( 8 | "fmt" 9 | "testing" 10 | 11 | "golang.org/x/text/internal/testtext" 12 | ) 13 | 14 | func TestLinking(t *testing.T) { 15 | base := getSize(t, `display.Tags(language.English).Name(language.English)`) 16 | compact := getSize(t, `display.English.Languages().Name(language.English)`) 17 | 18 | if d := base - compact; d < 1.5*1024*1024 { 19 | t.Errorf("size(base)-size(compact) was %d; want > 1.5MB", base, compact) 20 | } 21 | } 22 | 23 | func getSize(t *testing.T, main string) int { 24 | size, err := testtext.CodeSize(fmt.Sprintf(body, main)) 25 | if err != nil { 26 | t.Skipf("skipping link size test; binary size could not be determined: %v", err) 27 | } 28 | return size 29 | } 30 | 31 | const body = `package main 32 | import ( 33 | "golang.org/x/text/language" 34 | "golang.org/x/text/language/display" 35 | ) 36 | func main() { 37 | %s 38 | } 39 | ` 40 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/language/gen_common.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | package main 8 | 9 | // This file contains code common to the maketables.go and the package code. 10 | 11 | // langAliasType is the type of an alias in langAliasMap. 12 | type langAliasType int8 13 | 14 | const ( 15 | langDeprecated langAliasType = iota 16 | langMacro 17 | langLegacy 18 | 19 | langAliasTypeUnknown langAliasType = -1 20 | ) 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/language/go1_1.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.2 6 | 7 | package language 8 | 9 | import "sort" 10 | 11 | func sortStable(s sort.Interface) { 12 | ss := stableSort{ 13 | s: s, 14 | pos: make([]int, s.Len()), 15 | } 16 | for i := range ss.pos { 17 | ss.pos[i] = i 18 | } 19 | sort.Sort(&ss) 20 | } 21 | 22 | type stableSort struct { 23 | s sort.Interface 24 | pos []int 25 | } 26 | 27 | func (s *stableSort) Len() int { 28 | return len(s.pos) 29 | } 30 | 31 | func (s *stableSort) Less(i, j int) bool { 32 | return s.s.Less(i, j) || !s.s.Less(j, i) && s.pos[i] < s.pos[j] 33 | } 34 | 35 | func (s *stableSort) Swap(i, j int) { 36 | s.s.Swap(i, j) 37 | s.pos[i], s.pos[j] = s.pos[j], s.pos[i] 38 | } 39 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/language/go1_2.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.2 6 | 7 | package language 8 | 9 | import "sort" 10 | 11 | var sortStable = sort.Stable 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/language/httpexample_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package language_test 6 | 7 | import ( 8 | "fmt" 9 | "net/http" 10 | "strings" 11 | 12 | "golang.org/x/text/language" 13 | ) 14 | 15 | // matcher is a language.Matcher configured for all supported languages. 16 | var matcher = language.NewMatcher([]language.Tag{ 17 | language.BritishEnglish, 18 | language.Norwegian, 19 | language.German, 20 | }) 21 | 22 | // handler is a http.HandlerFunc. 23 | func handler(w http.ResponseWriter, r *http.Request) { 24 | t, q, err := language.ParseAcceptLanguage(r.Header.Get("Accept-Language")) 25 | // We ignore the error: the default language will be selected for t == nil. 26 | tag, _, _ := matcher.Match(t...) 27 | fmt.Printf("%5v (t: %6v; q: %3v; err: %v)\n", tag, t, q, err) 28 | } 29 | 30 | func ExampleParseAcceptLanguage() { 31 | for _, al := range []string{ 32 | "nn;q=0.3, en-us;q=0.8, en,", 33 | "gsw, en;q=0.7, en-US;q=0.8", 34 | "gsw, nl, da", 35 | "invalid", 36 | } { 37 | // Create dummy request with Accept-Language set and pass it to handler. 38 | r, _ := http.NewRequest("GET", "example.com", strings.NewReader("Hello")) 39 | r.Header.Set("Accept-Language", al) 40 | handler(nil, r) 41 | } 42 | 43 | // Output: 44 | // en-GB (t: [ en en-US nn]; q: [ 1 0.8 0.3]; err: ) 45 | // en-GB (t: [ gsw en-US en]; q: [ 1 0.8 0.7]; err: ) 46 | // de (t: [ gsw nl da]; q: [ 1 1 1]; err: ) 47 | // en-GB (t: []; q: []; err: language: tag is not well-formed) 48 | } 49 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/transform/examples_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package transform_test 6 | 7 | import ( 8 | "fmt" 9 | "unicode" 10 | 11 | "golang.org/x/text/transform" 12 | "golang.org/x/text/unicode/norm" 13 | ) 14 | 15 | func ExampleRemoveFunc() { 16 | input := []byte(`tschüß; до свидания`) 17 | 18 | b := make([]byte, len(input)) 19 | 20 | t := transform.RemoveFunc(unicode.IsSpace) 21 | n, _, _ := t.Transform(b, input, true) 22 | fmt.Println(string(b[:n])) 23 | 24 | t = transform.RemoveFunc(func(r rune) bool { 25 | return !unicode.Is(unicode.Latin, r) 26 | }) 27 | n, _, _ = t.Transform(b, input, true) 28 | fmt.Println(string(b[:n])) 29 | 30 | n, _, _ = t.Transform(b, norm.NFD.Bytes(input), true) 31 | fmt.Println(string(b[:n])) 32 | 33 | // Output: 34 | // tschüß;досвидания 35 | // tschüß 36 | // tschuß 37 | } 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/example_iter_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm_test 6 | 7 | import ( 8 | "bytes" 9 | "fmt" 10 | "unicode/utf8" 11 | 12 | "golang.org/x/text/unicode/norm" 13 | ) 14 | 15 | // EqualSimple uses a norm.Iter to compare two non-normalized 16 | // strings for equivalence. 17 | func EqualSimple(a, b string) bool { 18 | var ia, ib norm.Iter 19 | ia.InitString(norm.NFKD, a) 20 | ib.InitString(norm.NFKD, b) 21 | for !ia.Done() && !ib.Done() { 22 | if !bytes.Equal(ia.Next(), ib.Next()) { 23 | return false 24 | } 25 | } 26 | return ia.Done() && ib.Done() 27 | } 28 | 29 | // FindPrefix finds the longest common prefix of ASCII characters 30 | // of a and b. 31 | func FindPrefix(a, b string) int { 32 | i := 0 33 | for ; i < len(a) && i < len(b) && a[i] < utf8.RuneSelf && a[i] == b[i]; i++ { 34 | } 35 | return i 36 | } 37 | 38 | // EqualOpt is like EqualSimple, but optimizes the special 39 | // case for ASCII characters. 40 | func EqualOpt(a, b string) bool { 41 | n := FindPrefix(a, b) 42 | a, b = a[n:], b[n:] 43 | var ia, ib norm.Iter 44 | ia.InitString(norm.NFKD, a) 45 | ib.InitString(norm.NFKD, b) 46 | for !ia.Done() && !ib.Done() { 47 | if !bytes.Equal(ia.Next(), ib.Next()) { 48 | return false 49 | } 50 | if n := int64(FindPrefix(a[ia.Pos():], b[ib.Pos():])); n != 0 { 51 | ia.Seek(n, 1) 52 | ib.Seek(n, 1) 53 | } 54 | } 55 | return ia.Done() && ib.Done() 56 | } 57 | 58 | var compareTests = []struct{ a, b string }{ 59 | {"aaa", "aaa"}, 60 | {"aaa", "aab"}, 61 | {"a\u0300a", "\u00E0a"}, 62 | {"a\u0300\u0320b", "a\u0320\u0300b"}, 63 | {"\u1E0A\u0323", "\x44\u0323\u0307"}, 64 | // A character that decomposes into multiple segments 65 | // spans several iterations. 66 | {"\u3304", "\u30A4\u30CB\u30F3\u30AF\u3099"}, 67 | } 68 | 69 | func ExampleIter() { 70 | for i, t := range compareTests { 71 | r0 := EqualSimple(t.a, t.b) 72 | r1 := EqualOpt(t.a, t.b) 73 | fmt.Printf("%d: %v %v\n", i, r0, r1) 74 | } 75 | // Output: 76 | // 0: true true 77 | // 1: false false 78 | // 2: true true 79 | // 3: true true 80 | // 4: true true 81 | // 5: true true 82 | } 83 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm_test 6 | 7 | import ( 8 | "fmt" 9 | 10 | "golang.org/x/text/unicode/norm" 11 | ) 12 | 13 | func ExampleNextBoundary() { 14 | s := norm.NFD.String("Mêlée") 15 | 16 | for i := 0; i < len(s); { 17 | d := norm.NFC.NextBoundaryInString(s[i:], true) 18 | fmt.Printf("%[1]s: %+[1]q\n", s[i:i+d]) 19 | i += d 20 | } 21 | // Output: 22 | // M: "M" 23 | // ê: "e\u0302" 24 | // l: "l" 25 | // é: "e\u0301" 26 | // e: "e" 27 | } 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/forminfo_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build test 6 | 7 | package norm 8 | 9 | import "testing" 10 | 11 | func TestProperties(t *testing.T) { 12 | var d runeData 13 | CK := [2]string{"C", "K"} 14 | for k, r := 1, rune(0); r < 0x2ffff; r++ { 15 | if k < len(testData) && r == testData[k].r { 16 | d = testData[k] 17 | k++ 18 | } 19 | s := string(r) 20 | for j, p := range []Properties{NFC.PropertiesString(s), NFKC.PropertiesString(s)} { 21 | f := d.f[j] 22 | if p.CCC() != d.ccc { 23 | t.Errorf("%U: ccc(%s): was %d; want %d %X", r, CK[j], p.CCC(), d.ccc, p.index) 24 | } 25 | if p.isYesC() != (f.qc == Yes) { 26 | t.Errorf("%U: YesC(%s): was %v; want %v", r, CK[j], p.isYesC(), f.qc == Yes) 27 | } 28 | if p.combinesBackward() != (f.qc == Maybe) { 29 | t.Errorf("%U: combines backwards(%s): was %v; want %v", r, CK[j], p.combinesBackward(), f.qc == Maybe) 30 | } 31 | if p.nLeadingNonStarters() != d.nLead { 32 | t.Errorf("%U: nLead(%s): was %d; want %d %#v %#v", r, CK[j], p.nLeadingNonStarters(), d.nLead, p, d) 33 | } 34 | if p.nTrailingNonStarters() != d.nTrail { 35 | t.Errorf("%U: nTrail(%s): was %d; want %d %#v %#v", r, CK[j], p.nTrailingNonStarters(), d.nTrail, p, d) 36 | } 37 | if p.combinesForward() != f.combinesForward { 38 | t.Errorf("%U: combines forward(%s): was %v; want %v %#v", r, CK[j], p.combinesForward(), f.combinesForward, p) 39 | } 40 | // Skip Hangul as it is algorithmically computed. 41 | if r >= hangulBase && r < hangulEnd { 42 | continue 43 | } 44 | if p.hasDecomposition() { 45 | if has := f.decomposition != ""; !has { 46 | t.Errorf("%U: hasDecomposition(%s): was %v; want %v", r, CK[j], p.hasDecomposition(), has) 47 | } 48 | if string(p.Decomposition()) != f.decomposition { 49 | t.Errorf("%U: decomp(%s): was %+q; want %+q", r, CK[j], p.Decomposition(), f.decomposition) 50 | } 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/input.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | import "unicode/utf8" 8 | 9 | type input struct { 10 | str string 11 | bytes []byte 12 | } 13 | 14 | func inputBytes(str []byte) input { 15 | return input{bytes: str} 16 | } 17 | 18 | func inputString(str string) input { 19 | return input{str: str} 20 | } 21 | 22 | func (in *input) setBytes(str []byte) { 23 | in.str = "" 24 | in.bytes = str 25 | } 26 | 27 | func (in *input) setString(str string) { 28 | in.str = str 29 | in.bytes = nil 30 | } 31 | 32 | func (in *input) _byte(p int) byte { 33 | if in.bytes == nil { 34 | return in.str[p] 35 | } 36 | return in.bytes[p] 37 | } 38 | 39 | func (in *input) skipASCII(p, max int) int { 40 | if in.bytes == nil { 41 | for ; p < max && in.str[p] < utf8.RuneSelf; p++ { 42 | } 43 | } else { 44 | for ; p < max && in.bytes[p] < utf8.RuneSelf; p++ { 45 | } 46 | } 47 | return p 48 | } 49 | 50 | func (in *input) skipContinuationBytes(p int) int { 51 | if in.bytes == nil { 52 | for ; p < len(in.str) && !utf8.RuneStart(in.str[p]); p++ { 53 | } 54 | } else { 55 | for ; p < len(in.bytes) && !utf8.RuneStart(in.bytes[p]); p++ { 56 | } 57 | } 58 | return p 59 | } 60 | 61 | func (in *input) appendSlice(buf []byte, b, e int) []byte { 62 | if in.bytes != nil { 63 | return append(buf, in.bytes[b:e]...) 64 | } 65 | for i := b; i < e; i++ { 66 | buf = append(buf, in.str[i]) 67 | } 68 | return buf 69 | } 70 | 71 | func (in *input) copySlice(buf []byte, b, e int) int { 72 | if in.bytes == nil { 73 | return copy(buf, in.str[b:e]) 74 | } 75 | return copy(buf, in.bytes[b:e]) 76 | } 77 | 78 | func (in *input) charinfoNFC(p int) (uint16, int) { 79 | if in.bytes == nil { 80 | return nfcData.lookupString(in.str[p:]) 81 | } 82 | return nfcData.lookup(in.bytes[p:]) 83 | } 84 | 85 | func (in *input) charinfoNFKC(p int) (uint16, int) { 86 | if in.bytes == nil { 87 | return nfkcData.lookupString(in.str[p:]) 88 | } 89 | return nfkcData.lookup(in.bytes[p:]) 90 | } 91 | 92 | func (in *input) hangul(p int) (r rune) { 93 | if in.bytes == nil { 94 | if !isHangulString(in.str[p:]) { 95 | return 0 96 | } 97 | r, _ = utf8.DecodeRuneInString(in.str[p:]) 98 | } else { 99 | if !isHangul(in.bytes[p:]) { 100 | return 0 101 | } 102 | r, _ = utf8.DecodeRune(in.bytes[p:]) 103 | } 104 | return r 105 | } 106 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/norm_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm_test 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | func TestPlaceHolder(t *testing.T) { 12 | // Does nothing, just allows the Makefile to be canonical 13 | // while waiting for the package itself to be written. 14 | } 15 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/readwriter_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | import ( 8 | "bytes" 9 | "fmt" 10 | "testing" 11 | ) 12 | 13 | var bufSizes = []int{1, 2, 3, 4, 5, 6, 7, 8, 100, 101, 102, 103, 4000, 4001, 4002, 4003} 14 | 15 | func readFunc(size int) appendFunc { 16 | return func(f Form, out []byte, s string) []byte { 17 | out = append(out, s...) 18 | r := f.Reader(bytes.NewBuffer(out)) 19 | buf := make([]byte, size) 20 | result := []byte{} 21 | for n, err := 0, error(nil); err == nil; { 22 | n, err = r.Read(buf) 23 | result = append(result, buf[:n]...) 24 | } 25 | return result 26 | } 27 | } 28 | 29 | func TestReader(t *testing.T) { 30 | for _, s := range bufSizes { 31 | name := fmt.Sprintf("TestReader%d", s) 32 | runNormTests(t, name, readFunc(s)) 33 | } 34 | } 35 | 36 | func writeFunc(size int) appendFunc { 37 | return func(f Form, out []byte, s string) []byte { 38 | in := append(out, s...) 39 | result := new(bytes.Buffer) 40 | w := f.Writer(result) 41 | buf := make([]byte, size) 42 | for n := 0; len(in) > 0; in = in[n:] { 43 | n = copy(buf, in) 44 | _, _ = w.Write(buf[:n]) 45 | } 46 | w.Close() 47 | return result.Bytes() 48 | } 49 | } 50 | 51 | func TestWriter(t *testing.T) { 52 | for _, s := range bufSizes { 53 | name := fmt.Sprintf("TestWriter%d", s) 54 | runNormTests(t, name, writeFunc(s)) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/trie.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | type valueRange struct { 8 | value uint16 // header: value:stride 9 | lo, hi byte // header: lo:n 10 | } 11 | 12 | type sparseBlocks struct { 13 | values []valueRange 14 | offset []uint16 15 | } 16 | 17 | var nfcSparse = sparseBlocks{ 18 | values: nfcSparseValues[:], 19 | offset: nfcSparseOffset[:], 20 | } 21 | 22 | var nfkcSparse = sparseBlocks{ 23 | values: nfkcSparseValues[:], 24 | offset: nfkcSparseOffset[:], 25 | } 26 | 27 | var ( 28 | nfcData = newNfcTrie(0) 29 | nfkcData = newNfkcTrie(0) 30 | ) 31 | 32 | // lookupValue determines the type of block n and looks up the value for b. 33 | // For n < t.cutoff, the block is a simple lookup table. Otherwise, the block 34 | // is a list of ranges with an accompanying value. Given a matching range r, 35 | // the value for b is by r.value + (b - r.lo) * stride. 36 | func (t *sparseBlocks) lookup(n uint32, b byte) uint16 { 37 | offset := t.offset[n] 38 | header := t.values[offset] 39 | lo := offset + 1 40 | hi := lo + uint16(header.lo) 41 | for lo < hi { 42 | m := lo + (hi-lo)/2 43 | r := t.values[m] 44 | if r.lo <= b && b <= r.hi { 45 | return r.value + uint16(b-r.lo)*header.value 46 | } 47 | if b < r.lo { 48 | hi = m 49 | } else { 50 | lo = m + 1 51 | } 52 | } 53 | return 0 54 | } 55 | -------------------------------------------------------------------------------- /vendor/gopkg.in/sourcemap.v1/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.2 5 | - 1.3 6 | - 1.4 7 | - 1.5 8 | 9 | install: 10 | - mkdir -p $HOME/gopath/src/gopkg.in 11 | - mv $HOME/gopath/src/github.com/go-sourcemap/sourcemap $HOME/gopath/src/gopkg.in/sourcemap.v1 12 | - cd $HOME/gopath/src/gopkg.in/sourcemap.v1 13 | -------------------------------------------------------------------------------- /vendor/gopkg.in/sourcemap.v1/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 The github.com/go-sourcemap/sourcemap Contributors. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /vendor/gopkg.in/sourcemap.v1/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | go test ./... -test.v -test.cpu=1,2,4 3 | go test ./... -test.v -test.short -test.race 4 | -------------------------------------------------------------------------------- /vendor/gopkg.in/sourcemap.v1/README.md: -------------------------------------------------------------------------------- 1 | # Source Maps consumer for Golang [![Build Status](https://travis-ci.org/go-sourcemap/sourcemap.svg?branch=v1)](https://travis-ci.org/go-sourcemap/sourcemap) 2 | 3 | ## Installation 4 | 5 | Install: 6 | 7 | go get gopkg.in/sourcemap.v1 8 | 9 | ## Quickstart 10 | 11 | ```go 12 | func ExampleParse() { 13 | mapURL := "http://code.jquery.com/jquery-2.0.3.min.map" 14 | resp, err := http.Get(mapURL) 15 | if err != nil { 16 | panic(err) 17 | } 18 | defer resp.Body.Close() 19 | 20 | b, err := ioutil.ReadAll(resp.Body) 21 | if err != nil { 22 | panic(err) 23 | } 24 | 25 | smap, err := sourcemap.Parse(mapURL, b) 26 | if err != nil { 27 | panic(err) 28 | } 29 | 30 | line, column := 5, 6789 31 | file, fn, line, col, ok := smap.Source(line, column) 32 | fmt.Println(file, fn, line, col, ok) 33 | // Output: http://code.jquery.com/jquery-2.0.3.js apply 4360 27 true 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /vendor/gopkg.in/sourcemap.v1/base64vlq/base64_vlq.go: -------------------------------------------------------------------------------- 1 | package base64vlq 2 | 3 | import ( 4 | "io" 5 | ) 6 | 7 | const encodeStd = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 8 | 9 | const ( 10 | vlqBaseShift = 5 11 | vlqBase = 1 << vlqBaseShift 12 | vlqBaseMask = vlqBase - 1 13 | vlqSignBit = 1 14 | vlqContinuationBit = vlqBase 15 | ) 16 | 17 | var ( 18 | decodeMap [256]int 19 | ) 20 | 21 | func init() { 22 | for i := 0; i < len(encodeStd); i++ { 23 | decodeMap[encodeStd[i]] = i 24 | } 25 | } 26 | 27 | func toVLQSigned(n int) int { 28 | if n < 0 { 29 | return -n<<1 + 1 30 | } else { 31 | return n << 1 32 | } 33 | } 34 | 35 | func fromVLQSigned(n int) int { 36 | isNeg := n&vlqSignBit != 0 37 | n >>= 1 38 | if isNeg { 39 | return -n 40 | } 41 | return n 42 | } 43 | 44 | type Encoder struct { 45 | w io.ByteWriter 46 | } 47 | 48 | func NewEncoder(w io.ByteWriter) *Encoder { 49 | return &Encoder{ 50 | w: w, 51 | } 52 | } 53 | 54 | func (enc *Encoder) Encode(n int) error { 55 | n = toVLQSigned(n) 56 | for digit := vlqContinuationBit; digit&vlqContinuationBit != 0; { 57 | digit = n & vlqBaseMask 58 | n >>= vlqBaseShift 59 | if n > 0 { 60 | digit |= vlqContinuationBit 61 | } 62 | err := enc.w.WriteByte(encodeStd[digit]) 63 | if err != nil { 64 | return err 65 | } 66 | } 67 | return nil 68 | } 69 | 70 | type Decoder struct { 71 | r io.ByteReader 72 | } 73 | 74 | func NewDecoder(r io.ByteReader) *Decoder { 75 | return &Decoder{ 76 | r: r, 77 | } 78 | } 79 | 80 | func (dec *Decoder) Decode() (n int, err error) { 81 | shift := uint(0) 82 | for continuation := true; continuation; { 83 | c, err := dec.r.ReadByte() 84 | if err != nil { 85 | return 0, err 86 | } 87 | 88 | digit := decodeMap[c] 89 | continuation = digit&vlqContinuationBit != 0 90 | digit &= vlqBaseMask 91 | n = n + digit<