-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored tests and greatly improved test coverage
- Loading branch information
Showing
54 changed files
with
2,618 additions
and
874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* This file is part of b6b. | ||
* | ||
* Copyright 2017 Dima Krasner | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <inttypes.h> | ||
|
||
static inline uint32_t b6b_hash_init(void) | ||
{ | ||
return 0; | ||
} | ||
|
||
static inline void b6b_hash_update(uint32_t *hash, | ||
const unsigned char *buf, | ||
const size_t len) | ||
{ | ||
size_t i; | ||
|
||
for (i = 0; i < len; ++i) { | ||
*hash += buf[i] + (*hash << 10); | ||
*hash ^= (*hash >> 6); | ||
} | ||
} | ||
|
||
static inline void b6b_hash_finish(uint32_t *hash) | ||
{ | ||
*hash += (*hash << 3); | ||
*hash ^= (*hash >> 11); | ||
*hash += (*hash << 15); | ||
} | ||
|
||
__attribute__((nonnull(1))) | ||
uint32_t b6b_hash(const unsigned char *buf, const size_t len); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* This file is part of b6b. | ||
* | ||
* Copyright 2017 Dima Krasner | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <inttypes.h> | ||
|
||
#include <b6b.h> | ||
|
||
uint32_t b6b_hash(const unsigned char *buf, const size_t len) | ||
{ | ||
uint32_t h; | ||
|
||
h = b6b_hash_init(); | ||
b6b_hash_update(&h, buf, len); | ||
b6b_hash_finish(&h); | ||
|
||
return h; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* This file is part of b6b. | ||
* | ||
* Copyright 2017 Dima Krasner | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <assert.h> | ||
#include <string.h> | ||
|
||
#include <b6b.h> | ||
|
||
int main() | ||
{ | ||
struct b6b_interp interp; | ||
int occ[5] = {0, 0, 0, 0, 0}; | ||
|
||
assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE)); | ||
assert(b6b_call_copy(&interp, "{$choice}", 9) == B6B_ERR); | ||
b6b_interp_destroy(&interp); | ||
|
||
assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE)); | ||
assert(b6b_call_copy(&interp, "{$choice {}}", 12) == B6B_ERR); | ||
b6b_interp_destroy(&interp); | ||
|
||
assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE)); | ||
assert(b6b_call_copy(&interp, "{$choice a}", 11) == B6B_OK); | ||
assert(b6b_as_str(interp.fg->_)); | ||
assert(interp.fg->_->slen == 1); | ||
assert(strcmp(interp.fg->_->s, "a") == 0); | ||
b6b_interp_destroy(&interp); | ||
|
||
assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE)); | ||
assert(b6b_call_copy(&interp, "{$choice {a b}}", 15) == B6B_OK); | ||
assert(b6b_as_str(interp.fg->_)); | ||
assert(interp.fg->_->slen == 1); | ||
assert((strcmp(interp.fg->_->s, "a") == 0) || | ||
(strcmp(interp.fg->_->s, "b") == 0)); | ||
b6b_interp_destroy(&interp); | ||
|
||
assert(b6b_interp_new_argv(&interp, 0, NULL, B6B_OPT_TRACE)); | ||
do { | ||
assert(b6b_call_copy(&interp, "{$choice {0 1 2 3 4}}", 21) == B6B_OK); | ||
assert(b6b_as_int(interp.fg->_)); | ||
assert(interp.fg->_->i >= 0); | ||
assert(interp.fg->_->i <= 4); | ||
++occ[interp.fg->_->i]; | ||
} while (!occ[0] || !occ[1] || !occ[2] || !occ[3] || !occ[4]); | ||
b6b_interp_destroy(&interp); | ||
|
||
return EXIT_SUCCESS; | ||
} |
Oops, something went wrong.