1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ci: fix v test-cleancode

This commit is contained in:
Delyan Angelov
2021-01-25 11:26:20 +02:00
parent 94fd3ff431
commit 728344ff65
49 changed files with 353 additions and 356 deletions

View File

@@ -9,5 +9,5 @@ const (
// random returns a random time struct in *the past*.
pub fn random() time.Time {
return time.unix(int(rand.u64n(start_time_unix)))
return time.unix(int(rand.u64n(misc.start_time_unix)))
}

View File

@@ -13,9 +13,9 @@ const (
// but otherwise can be changed at will.
absolute_zero_year = i64(-292277022399) // as i64
seconds_per_minute = 60
seconds_per_hour = 60 * time.seconds_per_minute
seconds_per_day = 24 * time.seconds_per_hour
seconds_per_week = 7 * time.seconds_per_day
seconds_per_hour = 60 * seconds_per_minute
seconds_per_day = 24 * seconds_per_hour
seconds_per_week = 7 * seconds_per_day
days_per_400_years = 365 * 400 + 97
days_per_100_years = 365 * 100 + 24
days_per_4_years = 365 * 4 + 1
@@ -392,11 +392,11 @@ pub type Duration = i64
pub const (
nanosecond = Duration(1)
microsecond = Duration(1000 * time.nanosecond)
millisecond = Duration(1000 * time.microsecond)
second = Duration(1000 * time.millisecond)
minute = Duration(60 * time.second)
hour = Duration(60 * time.minute)
microsecond = Duration(1000 * nanosecond)
millisecond = Duration(1000 * microsecond)
second = Duration(1000 * millisecond)
minute = Duration(60 * second)
hour = Duration(60 * minute)
infinite = Duration(-1)
)

View File

@@ -40,10 +40,10 @@ fn init_time_base() C.mach_timebase_info_data_t {
fn sys_mono_now_darwin() u64 {
tm := C.mach_absolute_time()
if time_base.denom == 0 {
C.mach_timebase_info(&time_base)
if time.time_base.denom == 0 {
C.mach_timebase_info(&time.time_base)
}
return (tm - start_time) * time_base.numer / time_base.denom
return (tm - time.start_time) * time.time_base.numer / time.time_base.denom
}
// NB: vpc_now_darwin is used by `v -profile` .
@@ -51,10 +51,10 @@ fn sys_mono_now_darwin() u64 {
[inline]
fn vpc_now_darwin() u64 {
tm := C.mach_absolute_time()
if time_base.denom == 0 {
C.mach_timebase_info(&time_base)
if time.time_base.denom == 0 {
C.mach_timebase_info(&time.time_base)
}
return (tm - start_time) * time_base.numer / time_base.denom
return (tm - time.start_time) * time.time_base.numer / time.time_base.denom
}
// darwin_now returns a better precision current time for Darwin based operating system

View File

@@ -19,70 +19,70 @@ fn test_now_format() {
}
fn test_format() {
assert '11.07.1980 21:23' == time_to_test.get_fmt_str(.dot, .hhmm24, .ddmmyyyy)
assert '11.07.1980 21:23' == main.time_to_test.get_fmt_str(.dot, .hhmm24, .ddmmyyyy)
}
fn test_hhmm() {
assert '21:23' == time_to_test.hhmm()
assert '21:23' == main.time_to_test.hhmm()
}
fn test_hhmm12() {
assert '9:23 p.m.' == time_to_test.hhmm12()
assert '9:23 p.m.' == main.time_to_test.hhmm12()
}
fn test_hhmmss() {
assert '21:23:42' == time_to_test.hhmmss()
assert '21:23:42' == main.time_to_test.hhmmss()
}
fn test_ymmdd() {
assert '1980-07-11' == time_to_test.ymmdd()
assert '1980-07-11' == main.time_to_test.ymmdd()
}
fn test_ddmmy() {
assert '11.07.1980' == time_to_test.ddmmy()
assert '11.07.1980' == main.time_to_test.ddmmy()
}
fn test_md() {
assert 'Jul 11' == time_to_test.md()
assert 'Jul 11' == main.time_to_test.md()
}
fn test_get_fmt_time_str() {
assert '21:23:42' == time_to_test.get_fmt_time_str(.hhmmss24)
assert '21:23' == time_to_test.get_fmt_time_str(.hhmm24)
assert '9:23:42 p.m.' == time_to_test.get_fmt_time_str(.hhmmss12)
assert '9:23 p.m.' == time_to_test.get_fmt_time_str(.hhmm12)
assert '21:23:42' == main.time_to_test.get_fmt_time_str(.hhmmss24)
assert '21:23' == main.time_to_test.get_fmt_time_str(.hhmm24)
assert '9:23:42 p.m.' == main.time_to_test.get_fmt_time_str(.hhmmss12)
assert '9:23 p.m.' == main.time_to_test.get_fmt_time_str(.hhmm12)
}
fn test_get_fmt_date_str() {
assert '11.07.1980' == time_to_test.get_fmt_date_str(.dot, .ddmmyyyy)
assert '11/07/1980' == time_to_test.get_fmt_date_str(.slash, .ddmmyyyy)
assert '11-07-1980' == time_to_test.get_fmt_date_str(.hyphen, .ddmmyyyy)
assert '11 07 1980' == time_to_test.get_fmt_date_str(.space, .ddmmyyyy)
assert '07.11.1980' == time_to_test.get_fmt_date_str(.dot, .mmddyyyy)
assert '07/11/1980' == time_to_test.get_fmt_date_str(.slash, .mmddyyyy)
assert '07-11-1980' == time_to_test.get_fmt_date_str(.hyphen, .mmddyyyy)
assert '07 11 1980' == time_to_test.get_fmt_date_str(.space, .mmddyyyy)
assert '11.07.80' == time_to_test.get_fmt_date_str(.dot, .ddmmyy)
assert '11/07/80' == time_to_test.get_fmt_date_str(.slash, .ddmmyy)
assert '11-07-80' == time_to_test.get_fmt_date_str(.hyphen, .ddmmyy)
assert '11 07 80' == time_to_test.get_fmt_date_str(.space, .ddmmyy)
assert '07.11.80' == time_to_test.get_fmt_date_str(.dot, .mmddyy)
assert '07/11/80' == time_to_test.get_fmt_date_str(.slash, .mmddyy)
assert '07-11-80' == time_to_test.get_fmt_date_str(.hyphen, .mmddyy)
assert '07 11 80' == time_to_test.get_fmt_date_str(.space, .mmddyy)
assert 'Jul 11' == time_to_test.get_fmt_date_str(.space, .mmmd)
assert 'Jul 11' == time_to_test.get_fmt_date_str(.space, .mmmdd)
assert 'Jul 11 1980' == time_to_test.get_fmt_date_str(.space, .mmmddyyyy)
assert '1980-07-11' == time_to_test.get_fmt_date_str(.hyphen, .yyyymmdd)
assert '11.07.1980' == main.time_to_test.get_fmt_date_str(.dot, .ddmmyyyy)
assert '11/07/1980' == main.time_to_test.get_fmt_date_str(.slash, .ddmmyyyy)
assert '11-07-1980' == main.time_to_test.get_fmt_date_str(.hyphen, .ddmmyyyy)
assert '11 07 1980' == main.time_to_test.get_fmt_date_str(.space, .ddmmyyyy)
assert '07.11.1980' == main.time_to_test.get_fmt_date_str(.dot, .mmddyyyy)
assert '07/11/1980' == main.time_to_test.get_fmt_date_str(.slash, .mmddyyyy)
assert '07-11-1980' == main.time_to_test.get_fmt_date_str(.hyphen, .mmddyyyy)
assert '07 11 1980' == main.time_to_test.get_fmt_date_str(.space, .mmddyyyy)
assert '11.07.80' == main.time_to_test.get_fmt_date_str(.dot, .ddmmyy)
assert '11/07/80' == main.time_to_test.get_fmt_date_str(.slash, .ddmmyy)
assert '11-07-80' == main.time_to_test.get_fmt_date_str(.hyphen, .ddmmyy)
assert '11 07 80' == main.time_to_test.get_fmt_date_str(.space, .ddmmyy)
assert '07.11.80' == main.time_to_test.get_fmt_date_str(.dot, .mmddyy)
assert '07/11/80' == main.time_to_test.get_fmt_date_str(.slash, .mmddyy)
assert '07-11-80' == main.time_to_test.get_fmt_date_str(.hyphen, .mmddyy)
assert '07 11 80' == main.time_to_test.get_fmt_date_str(.space, .mmddyy)
assert 'Jul 11' == main.time_to_test.get_fmt_date_str(.space, .mmmd)
assert 'Jul 11' == main.time_to_test.get_fmt_date_str(.space, .mmmdd)
assert 'Jul 11 1980' == main.time_to_test.get_fmt_date_str(.space, .mmmddyyyy)
assert '1980-07-11' == main.time_to_test.get_fmt_date_str(.hyphen, .yyyymmdd)
}
fn test_get_fmt_str() {
// Since get_fmt_time_str and get_fmt_date_str do have comprehensive
// tests I don't want to exaggerate here with all possible
// combinations.
assert '11.07.1980 21:23:42' == time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy)
assert '11.07.1980 21:23:42' == main.time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy)
}
fn test_utc_string() {
assert 'Fri, 11 Jul 1980 21:23:42 UTC' == time_to_test.utc_string()
assert 'Fri, 11 Jul 1980 21:23:42 UTC' == main.time_to_test.utc_string()
}

View File

@@ -83,17 +83,17 @@ fn test_unix() {
}
fn test_format_ss() {
assert '11.07.1980 21:23:42' == time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy)
assert '11.07.1980 21:23:42' == main.time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy)
}
fn test_format_ss_milli() {
assert '11.07.1980 21:23:42.123' == time_to_test.get_fmt_str(.dot, .hhmmss24_milli, .ddmmyyyy)
assert '1980-07-11 21:23:42.123' == time_to_test.format_ss_milli()
assert '11.07.1980 21:23:42.123' == main.time_to_test.get_fmt_str(.dot, .hhmmss24_milli, .ddmmyyyy)
assert '1980-07-11 21:23:42.123' == main.time_to_test.format_ss_milli()
}
fn test_format_ss_micro() {
assert '11.07.1980 21:23:42.123456' == time_to_test.get_fmt_str(.dot, .hhmmss24_micro, .ddmmyyyy)
assert '1980-07-11 21:23:42.123456' == time_to_test.format_ss_micro()
assert '11.07.1980 21:23:42.123456' == main.time_to_test.get_fmt_str(.dot, .hhmmss24_micro, .ddmmyyyy)
assert '1980-07-11 21:23:42.123456' == main.time_to_test.format_ss_micro()
}
fn test_smonth() {
@@ -153,12 +153,12 @@ fn test_add() {
d_seconds := 3
d_microseconds := 13
duration := time.Duration(d_seconds * time.second + d_microseconds * time.microsecond)
t1 := time_to_test
t2 := time_to_test.add(duration)
t1 := main.time_to_test
t2 := main.time_to_test.add(duration)
assert t2.second == t1.second + d_seconds
assert t2.microsecond == t1.microsecond + d_microseconds
assert t2.unix == t1.unix + u64(d_seconds)
t3 := time_to_test.add(-duration)
t3 := main.time_to_test.add(-duration)
assert t3.second == t1.second - d_seconds
assert t3.microsecond == t1.microsecond - d_microseconds
assert t3.unix == t1.unix - u64(d_seconds)
@@ -166,13 +166,13 @@ fn test_add() {
fn test_add_days() {
num_of_days := 3
t := time_to_test.add_days(num_of_days)
assert t.day == time_to_test.day + num_of_days
assert t.unix == time_to_test.unix + 86400 * u64(num_of_days)
t := main.time_to_test.add_days(num_of_days)
assert t.day == main.time_to_test.day + num_of_days
assert t.unix == main.time_to_test.unix + 86400 * u64(num_of_days)
}
fn test_str() {
assert '1980-07-11 21:23:42' == time_to_test.str()
assert '1980-07-11 21:23:42' == main.time_to_test.str()
}
// not optimal test but will find obvious bugs

View File

@@ -75,7 +75,7 @@ fn init_win_time_start() u64 {
pub fn sys_mono_now() u64 {
tm := u64(0)
C.QueryPerformanceCounter(&tm) // XP or later never fail
return (tm - start_time) * 1000000000 / freq_time
return (tm - time.start_time) * 1000000000 / time.freq_time
}
// NB: vpc_now is used by `v -profile` .