use the zig formatter

This commit is contained in:
Folkert 2020-12-01 21:26:37 +01:00
parent 92544e5b07
commit 1589e688b3
4 changed files with 6995 additions and 7069 deletions

View file

@ -38,7 +38,7 @@ pub fn build(b: *Builder) void {
const ir_to_bitcode = b.addSystemCommand(&[_][]const u8{
"llvm-as-10",
ir_out_file,
bitcode_path_arg
bitcode_path_arg,
});
const bicode = b.step("bc", "Build LLVM ir and convert to bitcode");

View file

@ -49,8 +49,7 @@ test "Bound Class" {
fn graphemeBreakSimple(lbc: BoundClass, tbc: BoundClass) bool {
const lbc_u8 = @enumToInt(lbc);
const tbc_u8 = @enumToInt(tbc);
return (
if (lbc_u8 == @enumToInt(BoundClass.START)) // GB1
return (if (lbc_u8 == @enumToInt(BoundClass.START)) // GB1
true
else if (lbc_u8 == @enumToInt(BoundClass.CR) and tbc_u8 == @enumToInt(BoundClass.LF)) // GB3
false
@ -71,8 +70,7 @@ fn graphemeBreakSimple(lbc: BoundClass, tbc: BoundClass) bool {
else if (lbc_u8 == @enumToInt(BoundClass.REGIONAL_INDICATOR) and tbc_u8 == @enumToInt(BoundClass.REGIONAL_INDICATOR)) // GB12/13 (requires additional handling below)
false
else // GB999
true
);
true);
}
// https://github.com/JuliaStrings/utf8proc/blob/master/utf8proc.c#L291
@ -151,11 +149,7 @@ test "codepointToBoundClass: invalid" {
// which require this state will not be applied, essentially matching the rules in
// Unicode 8.0.0.
pub fn isGraphemeBreak(codePoint1: u21, codePoint2: u21, opt_state_ptr: *?BoundClass) bool {
return graphemeBreakExtended(
codepointToBoundClass(codePoint1).*,
codepointToBoundClass(codePoint2).*,
opt_state_ptr
);
return graphemeBreakExtended(codepointToBoundClass(codePoint1).*, codepointToBoundClass(codePoint2).*, opt_state_ptr);
}
// https://github.com/JuliaStrings/utf8proc/blob/master/utf8proc_data.c

View file

@ -4,18 +4,22 @@ const testing = std.testing;
// Num Module
const num = @import("num.zig");
comptime { exportNumFn(num.atan, "atan"); }
comptime { exportNumFn(num.isFinite, "is_finite"); }
comptime { exportNumFn(num.powInt, "pow_int"); }
comptime { exportNumFn(num.acos, "acos"); }
comptime { exportNumFn(num.asin, "asin"); }
comptime {
exportNumFn(num.atan, "atan");
exportNumFn(num.isFinite, "is_finite");
exportNumFn(num.powInt, "pow_int");
exportNumFn(num.acos, "acos");
exportNumFn(num.asin, "asin");
}
// Str Module
const str = @import("str.zig");
comptime { exportStrFn(str.strSplitInPlace, "str_split_in_place"); }
comptime { exportStrFn(str.countSegments, "count_segments"); }
comptime { exportStrFn(str.countGraphemeClusters, "count_grapheme_clusters"); }
comptime { exportStrFn(str.startsWith, "starts_with"); }
comptime {
exportStrFn(str.strSplitInPlace, "str_split_in_place");
exportStrFn(str.countSegments, "count_segments");
exportStrFn(str.countGraphemeClusters, "count_grapheme_clusters");
exportStrFn(str.startsWith, "starts_with");
}
// Export helpers - Must be run inside a comptime
fn exportBuiltinFn(comptime fn_target: anytype, comptime fn_name: []const u8) void {

View file

@ -14,7 +14,7 @@ const RocStr = struct {
pub fn empty() RocStr {
return RocStr{
.str_len = 0,
.str_bytes = null
.str_bytes = null,
};
}
@ -53,7 +53,7 @@ const RocStr = struct {
return RocStr{
.str_bytes = new_bytes,
.str_len = length
.str_len = length,
};
}
}
@ -199,14 +199,7 @@ const RocStr = struct {
// Str.split
pub fn strSplitInPlace(
array: [*]RocStr,
array_len: usize,
str_bytes: [*]const u8,
str_len: usize,
delimiter_bytes_ptrs: [*]const u8,
delimiter_len: usize
) callconv(.C) void {
pub fn strSplitInPlace(array: [*]RocStr, array_len: usize, str_bytes: [*]const u8, str_len: usize, delimiter_bytes_ptrs: [*]const u8, delimiter_len: usize) callconv(.C) void {
var ret_array_index: usize = 0;
var sliceStart_index: usize = 0;
var str_index: usize = 0;
@ -247,7 +240,6 @@ pub fn strSplitInPlace(
test "strSplitInPlace: no delimiter" {
// Str.split "abc" "!" == [ "abc" ]
var str: [3]u8 = "abc".*;
const str_ptr: [*]const u8 = &str;
@ -257,14 +249,7 @@ test "strSplitInPlace: no delimiter" {
var array: [1]RocStr = undefined;
const array_ptr: [*]RocStr = &array;
strSplitInPlace(
array_ptr,
1,
str_ptr,
3,
delimiter_ptr,
1
);
strSplitInPlace(array_ptr, 1, str_ptr, 3, delimiter_ptr, 1);
var expected = [1]RocStr{
RocStr.init(str_ptr, 3),
@ -300,14 +285,7 @@ test "strSplitInPlace: empty end" {
};
const array_ptr: [*]RocStr = &array;
strSplitInPlace(
array_ptr,
array_len,
str_ptr,
str_len,
delimiter_ptr,
delimiter_len
);
strSplitInPlace(array_ptr, array_len, str_ptr, str_len, delimiter_ptr, delimiter_len);
const first_expected_str_len: usize = 1;
var first_expected_str: [first_expected_str_len]u8 = "1".*;
@ -329,7 +307,6 @@ test "strSplitInPlace: empty end" {
test "strSplitInPlace: delimiter on sides" {
// Str.split "tttghittt" "ttt" == [ "", "ghi", "" ]
const str_len: usize = 9;
var str: [str_len]u8 = "tttghittt".*;
const str_ptr: [*]u8 = &str;
@ -346,14 +323,7 @@ test "strSplitInPlace: delimiter on sides" {
};
const array_ptr: [*]RocStr = &array;
strSplitInPlace(
array_ptr,
array_len,
str_ptr,
str_len,
delimiter_ptr,
delimiter_len
);
strSplitInPlace(array_ptr, array_len, str_ptr, str_len, delimiter_ptr, delimiter_len);
const expected_str_len: usize = 3;
var expected_str: [expected_str_len]u8 = "ghi".*;
@ -369,7 +339,6 @@ test "strSplitInPlace: delimiter on sides" {
test "strSplitInPlace: three pieces" {
// Str.split "a!b!c" "!" == [ "a", "b", "c" ]
const str_len: usize = 5;
var str: [str_len]u8 = "a!b!c".*;
const str_ptr: [*]u8 = &str;
@ -382,14 +351,7 @@ test "strSplitInPlace: three pieces" {
var array: [array_len]RocStr = undefined;
const array_ptr: [*]RocStr = &array;
strSplitInPlace(
array_ptr,
array_len,
str_ptr,
str_len,
delimiter_ptr,
delimiter_len
);
strSplitInPlace(array_ptr, array_len, str_ptr, str_len, delimiter_ptr, delimiter_len);
var a: [1]u8 = "a".*;
const a_ptr: [*]u8 = &a;
@ -412,7 +374,7 @@ test "strSplitInPlace: three pieces" {
RocStr{
.str_bytes = c_ptr,
.str_len = 1,
}
},
};
// TODO: fix those tests
@ -426,12 +388,7 @@ test "strSplitInPlace: three pieces" {
// It is used to count how many segments the input `_str`
// needs to be broken into, so that we can allocate a array
// of that size. It always returns at least 1.
pub fn countSegments(
str_bytes: [*]u8,
str_len: usize,
delimiter_bytes_ptrs: [*]u8,
delimiter_len: usize
) callconv(.C) usize {
pub fn countSegments(str_bytes: [*]u8, str_len: usize, delimiter_bytes_ptrs: [*]u8, delimiter_len: usize) callconv(.C) usize {
var count: usize = 1;
if (str_len > delimiter_len) {
@ -469,7 +426,6 @@ pub fn countSegments(
test "countSegments: long delimiter" {
// Str.split "str" "delimiter" == [ "str" ]
// 1 segment
const str_len: usize = 3;
var str: [str_len]u8 = "str".*;
const str_ptr: [*]u8 = &str;
@ -478,12 +434,7 @@ test "countSegments: long delimiter" {
var delimiter: [delimiter_len]u8 = "delimiter".*;
const delimiter_ptr: [*]u8 = &delimiter;
const segments_count = countSegments(
str_ptr,
str_len,
delimiter_ptr,
delimiter_len
);
const segments_count = countSegments(str_ptr, str_len, delimiter_ptr, delimiter_len);
expectEqual(segments_count, 1);
}
@ -491,7 +442,6 @@ test "countSegments: long delimiter" {
test "countSegments: delimiter at start" {
// Str.split "hello there" "hello" == [ "", " there" ]
// 2 segments
const str_len: usize = 11;
var str: [str_len]u8 = "hello there".*;
const str_ptr: [*]u8 = &str;
@ -500,12 +450,7 @@ test "countSegments: delimiter at start" {
var delimiter: [delimiter_len]u8 = "hello".*;
const delimiter_ptr: [*]u8 = &delimiter;
const segments_count = countSegments(
str_ptr,
str_len,
delimiter_ptr,
delimiter_len
);
const segments_count = countSegments(str_ptr, str_len, delimiter_ptr, delimiter_len);
expectEqual(segments_count, 2);
}
@ -513,7 +458,6 @@ test "countSegments: delimiter at start" {
test "countSegments: delimiter interspered" {
// Str.split "a!b!c" "!" == [ "a", "b", "c" ]
// 3 segments
const str_len: usize = 5;
var str: [str_len]u8 = "a!b!c".*;
const str_ptr: [*]u8 = &str;
@ -522,12 +466,7 @@ test "countSegments: delimiter interspered" {
var delimiter: [delimiter_len]u8 = "!".*;
const delimiter_ptr: [*]u8 = &delimiter;
const segments_count = countSegments(
str_ptr,
str_len,
delimiter_ptr,
delimiter_len
);
const segments_count = countSegments(str_ptr, str_len, delimiter_ptr, delimiter_len);
expectEqual(segments_count, 3);
}
@ -545,11 +484,7 @@ pub fn countGraphemeClusters(bytes_ptr: [*]u8, bytes_len: usize) callconv(.C) u
var opt_last_codepoint: ?u21 = null;
while (iter.nextCodepoint()) |cur_codepoint| {
if (opt_last_codepoint) |last_codepoint| {
var did_break = grapheme.isGraphemeBreak(
last_codepoint,
cur_codepoint,
grapheme_break_state_ptr
);
var did_break = grapheme.isGraphemeBreak(last_codepoint, cur_codepoint, grapheme_break_state_ptr);
if (did_break) {
count += 1;
grapheme_break_state = null;
@ -615,15 +550,9 @@ test "countGraphemeClusters: emojis, ut8, and ascii characters" {
expectEqual(count, 10);
}
// Str.startsWith
pub fn startsWith(
bytes_ptr: [*]u8,
bytes_len: usize,
prefix_ptr: [*]u8,
prefix_len: usize
) callconv(.C) bool {
pub fn startsWith(bytes_ptr: [*]u8, bytes_len: usize, prefix_ptr: [*]u8, prefix_len: usize) callconv(.C) bool {
if (prefix_len > bytes_len) {
return false;
}
@ -639,7 +568,6 @@ pub fn startsWith(
return true;
}
test "startsWith: 123456789123456789 starts with 123456789123456789" {
const str_len: usize = 18;
var str: [str_len]u8 = "123456789123456789".*;