diff --git a/base/client.jl b/base/client.jl index f048bc9f58d43..3e5e16d51053f 100644 --- a/base/client.jl +++ b/base/client.jl @@ -225,7 +225,7 @@ function process_options(args::Array{Any,1}) # load juliarc now before processing any more options try_include(string(ENV["HOME"],"/.juliarc.jl")) startup = false - elseif begins_with(args[i], "--color") + elseif beginswith(args[i], "--color") if args[i] == "--color" color_set = true global have_color = true @@ -332,7 +332,7 @@ function _start() startup && try_include(joinpath(ENV["HOME"],".juliarc.jl")) if !color_set - @unix_only global have_color = (begins_with(get(ENV,"TERM",""),"xterm") || success(`tput setaf 0`)) + @unix_only global have_color = (beginswith(get(ENV,"TERM",""),"xterm") || success(`tput setaf 0`)) @windows_only global have_color = true end diff --git a/base/datafmt.jl b/base/datafmt.jl index f7bb92e76d33e..e64419f2b2402 100644 --- a/base/datafmt.jl +++ b/base/datafmt.jl @@ -12,7 +12,7 @@ function dlm_readrow(io::IO, dlm, eol::Char) else row = split(row_string, dlm, true) end - if ends_with(row[end], eol) + if endswith(row[end], eol) row[end] = chop(row[end]) end row diff --git a/base/deprecated.jl b/base/deprecated.jl index a2e670d294053..6144ecdf3679a 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -162,6 +162,16 @@ export PipeString @deprecate each_match eachmatch @deprecate function_loc functionloc @deprecate compile_hint precompile +@deprecate begins_with beginswith +@deprecate ends_with endswidth +@deprecate parse_float parsefloat +@deprecate parse_int parseint +@deprecate parse_bin(T,s) parseint(T,s,2) +@deprecate parse_bin(s) parseint(s,2) +@deprecate parse_oct(T,s) parseint(T,s,8) +@deprecate parse_oct(s) parseint(s,8) +@deprecate parse_hex(T,s) parseint(T,s,16) +@deprecate parse_hex(s) parseint(s,16) @deprecate expr(hd, a...) Expr(hd, a...) @deprecate expr(hd, a::Array{Any,1}) Expr(hd, a...) diff --git a/base/env.jl b/base/env.jl index 249573c02be3a..fed629fdb22e1 100644 --- a/base/env.jl +++ b/base/env.jl @@ -133,5 +133,5 @@ end ## misc environment-related functionality ## -tty_cols() = parse_int(Int32, get(ENV,"COLUMNS","80"), 10) -tty_rows() = parse_int(Int32, get(ENV,"LINES","25"), 10) +tty_cols() = parseint(Int32, get(ENV,"COLUMNS","80"), 10) +tty_rows() = parseint(Int32, get(ENV,"LINES","25"), 10) diff --git a/base/exports.jl b/base/exports.jl index a1a95e3b12960..b2fdff4a5c2ba 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -699,7 +699,7 @@ export # strings and text output ascii, - begins_with, + beginswith, char, charwidth, chomp, @@ -707,7 +707,7 @@ export chr2ind, bytestring, eachmatch, - ends_with, + endswith, escape_string, first_utf8_byte, ind2chr, @@ -762,11 +762,8 @@ export ndigits, ndigits0z, oct, - parse_bin, - parse_float, - parse_hex, - parse_int, - parse_oct, + parsefloat, + parseint, print, print_escaped, print_joined, diff --git a/base/floatfuncs.jl b/base/floatfuncs.jl index 0c6ac003f76af..6eb85d352fe7f 100644 --- a/base/floatfuncs.jl +++ b/base/floatfuncs.jl @@ -36,9 +36,9 @@ num2hex(x::Float64) = hex(box(Uint64,unbox(Float64,x)),16) function hex2num(s::String) if length(s) <= 8 - return box(Float32,unbox(Int32,parse_hex(Int32,s))) + return box(Float32,unbox(Int32,parseint(Int32,s,16))) end - return box(Float64,unbox(Int64,parse_hex(Int64,s))) + return box(Float64,unbox(Int64,parseint(Int64,s,16))) end @vectorize_1arg Real iround diff --git a/base/git.jl b/base/git.jl index 368fd29d281ce..4ea318e36ff7f 100644 --- a/base/git.jl +++ b/base/git.jl @@ -147,8 +147,8 @@ function merge_configs(Bc::Dict, Lc::Dict, Rc::Dict) # expunge removed submodules from left and right sides deleted = Set{ByteString}() for section in Bs - Ls & Rs - filter!((k,v)->!begins_with(k,"$section."),Lc) - filter!((k,v)->!begins_with(k,"$section."),Rc) + filter!((k,v)->!beginswith(k,"$section."),Lc) + filter!((k,v)->!beginswith(k,"$section."),Rc) add!(deleted, section) end # merge the remaining config key-value pairs diff --git a/base/help.jl b/base/help.jl index 39517ad454911..09f070704cdc3 100644 --- a/base/help.jl +++ b/base/help.jl @@ -17,7 +17,7 @@ end function decor_help_desc(func::String, mfunc::String, desc::String) sd = split(desc, '\n') for i = 1:length(sd) - if begins_with(sd[i], func) + if beginswith(sd[i], func) sd[i] = mfunc * sd[i][length(func)+1:end] else break @@ -54,7 +54,7 @@ function init_help() CATEGORY_DICT[cat] = {} end if !isempty(mod) - if begins_with(func, '@') + if beginswith(func, '@') mfunc = "@" * mod * "." * func[2:] else mfunc = mod * "." * func @@ -133,7 +133,7 @@ function help_for(fname::String, obj) found = true else macrocall = "" - if begins_with(fname, '@') + if beginswith(fname, '@') sfname = fname[2:] macrocall = "@" else diff --git a/base/loading.jl b/base/loading.jl index 5628adf1ff33d..074e56a895d29 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -9,7 +9,7 @@ function find_in_path(name::String) name[1] == '/' && return abspath(name) isfile(name) && return abspath(name) base = name - if ends_with(name,".jl") + if endswith(name,".jl") base = match(r"^(.*)\.jl$",name).captures[1] else name = string(base,".jl") diff --git a/base/multi.jl b/base/multi.jl index 9c2e27cf9e28f..1051d8ba647f3 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -947,7 +947,7 @@ end function parse_connection_info(str) m = match(r"^julia_worker:(\d+)#(.*)", str) if m != nothing - (m.captures[2], parse_int(Int16, m.captures[1])) + (m.captures[2], parseint(Int16, m.captures[1])) else ("", int16(-1)) end diff --git a/base/pkg.jl b/base/pkg.jl index 6a81ac1db022a..1a7960dd99b52 100644 --- a/base/pkg.jl +++ b/base/pkg.jl @@ -512,7 +512,7 @@ pull() = cd_pkgdir() do end # remove submodules that were deleted for section in deleted - if !begins_with(section,"submodule.") continue end + if !beginswith(section,"submodule.") continue end path = get(Lc,"$section.path",nothing) if path == nothing continue end run(`git rm -qrf --cached --ignore-unmatch -- $path`) diff --git a/base/printf.jl b/base/printf.jl index bb38fadd5447b..cb2d6a775e246 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -754,7 +754,7 @@ end _is_str_expr(ex) = isa(ex,Expr) && ex.head==:macrocall && isa(ex.args[1],Symbol) && - (ex.args[1] == :str || ends_with(string(ex.args[1]),"_str")) + (ex.args[1] == :str || endswith(string(ex.args[1]),"_str")) macro printf(args...) if length(args) == 0 diff --git a/base/random.jl b/base/random.jl index be0d7aa13bc64..b6b440ebe8823 100644 --- a/base/random.jl +++ b/base/random.jl @@ -55,7 +55,7 @@ function librandom_init() seed = reinterpret(Uint64, time()) seed = bitmix(seed, uint64(getpid())) try - seed = bitmix(seed, parse_int(Uint64, readall(`ifconfig`|`sha1sum`)[1:40], 16)) + seed = bitmix(seed, parseint(Uint64, readall(`ifconfig`|`sha1sum`)[1:40], 16)) catch # ignore end diff --git a/base/string.jl b/base/string.jl index a0b90ade5ca37..69c0914a3d5f2 100644 --- a/base/string.jl +++ b/base/string.jl @@ -230,7 +230,7 @@ hash(s::String) = hash(bytestring(s)) # begins with and ends with predicates -function begins_with(a::String, b::String) +function beginswith(a::String, b::String) i = start(a) j = start(b) while !done(a,i) && !done(b,i) @@ -240,9 +240,9 @@ function begins_with(a::String, b::String) end done(b,i) end -begins_with(a::String, c::Char) = !isempty(a) && a[start(a)] == c +beginswith(a::String, c::Char) = !isempty(a) && a[start(a)] == c -function ends_with(a::String, b::String) +function endswith(a::String, b::String) i = endof(a) j = endof(b) a1 = start(a) @@ -256,17 +256,17 @@ function ends_with(a::String, b::String) end j < b1 end -ends_with(a::String, c::Char) = !isempty(a) && a[end] == c +endswith(a::String, c::Char) = !isempty(a) && a[end] == c # faster comparisons for byte strings cmp(a::ByteString, b::ByteString) = cmp(a.data, b.data) isequal(a::ByteString, b::ByteString) = endof(a)==endof(b) && cmp(a,b)==0 -begins_with(a::ByteString, b::ByteString) = begins_with(a.data, b.data) +beginswith(a::ByteString, b::ByteString) = beginswith(a.data, b.data) -begins_with(a::Array{Uint8,1}, b::Array{Uint8,1}) = (length(a) >= length(b) && ccall(:strncmp, Int32, (Ptr{Uint8}, Ptr{Uint8}, Uint), a, b, length(b)) == 0) +beginswith(a::Array{Uint8,1}, b::Array{Uint8,1}) = (length(a) >= length(b) && ccall(:strncmp, Int32, (Ptr{Uint8}, Ptr{Uint8}, Uint), a, b, length(b)) == 0) -# TODO: fast ends_with +# TODO: fast endswith ## character column width function ## @@ -1052,7 +1052,7 @@ strip(s::String, chars::String) = lstrip(rstrip(s, chars), chars) ## string to integer functions ## -function parse_int{T<:Integer}(::Type{T}, s::String, base::Integer) +function parseint{T<:Integer}(::Type{T}, s::String, base::Integer) if !(2 <= base <= 36); error("invalid base: ",base); end i = start(s) while true @@ -1118,32 +1118,24 @@ function parse_int{T<:Integer}(::Type{T}, s::String, base::Integer) return n end -parse_int(s::String, base::Integer) = parse_int(Int,s,base) -parse_int(T::Type, s::String) = parse_int(T,s,10) -parse_int(s::String) = parse_int(Int,s,10) - -parse_bin(T::Type, s::String) = parse_int(T,s,2) -parse_oct(T::Type, s::String) = parse_int(T,s,8) -parse_hex(T::Type, s::String) = parse_int(T,s,16) - -parse_bin(s::String) = parse_int(Int,s,2) -parse_oct(s::String) = parse_int(Int,s,8) -parse_hex(s::String) = parse_int(Int,s,16) +parseint(s::String, base::Integer) = parseint(Int,s,base) +parseint(T::Type, s::String) = parseint(T,s,10) +parseint(s::String) = parseint(Int,s,10) integer (s::String) = int(s) unsigned(s::String) = uint(s) -int (s::String) = parse_int(Int,s) -uint (s::String) = parse_int(Uint,s) -int8 (s::String) = parse_int(Int8,s) -uint8 (s::String) = parse_int(Uint8,s) -int16 (s::String) = parse_int(Int16,s) -uint16 (s::String) = parse_int(Uint16,s) -int32 (s::String) = parse_int(Int32,s) -uint32 (s::String) = parse_int(Uint32,s) -int64 (s::String) = parse_int(Int64,s) -uint64 (s::String) = parse_int(Uint64,s) -int128 (s::String) = parse_int(Int128,s) -uint128 (s::String) = parse_int(Uint128,s) +int (s::String) = parseint(Int,s) +uint (s::String) = parseint(Uint,s) +int8 (s::String) = parseint(Int8,s) +uint8 (s::String) = parseint(Uint8,s) +int16 (s::String) = parseint(Int16,s) +uint16 (s::String) = parseint(Uint16,s) +int32 (s::String) = parseint(Int32,s) +uint32 (s::String) = parseint(Uint32,s) +int64 (s::String) = parseint(Int64,s) +uint64 (s::String) = parseint(Uint64,s) +int128 (s::String) = parseint(Int128,s) +uint128 (s::String) = parseint(Uint128,s) ## stringifying integers more efficiently ## @@ -1176,9 +1168,9 @@ begin end float(x::String) = float64(x) -parse_float(x::String) = float64(x) -parse_float(::Type{Float64}, x::String) = float64(x) -parse_float(::Type{Float32}, x::String) = float32(x) +parsefloat(x::String) = float64(x) +parsefloat(::Type{Float64}, x::String) = float64(x) +parsefloat(::Type{Float32}, x::String) = float32(x) for conv in (:float, :float32, :float64, :int, :int8, :int16, :int32, :int64, diff --git a/base/sysimg.jl b/base/sysimg.jl index 6ceda2e42e659..f5a46d19d7909 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -219,7 +219,7 @@ precompile(unshift!, (Array{WorkItem,1}, WorkItem)) precompile(enq_work, (WorkItem,)) precompile(pop!, (Array{WorkItem,1},)) precompile(string, (Int,)) -precompile(parse_int, (Type{Int}, ASCIIString, Int)) +precompile(parseint, (Type{Int}, ASCIIString, Int)) precompile(repeat, (ASCIIString, Int)) precompile(KeyError, (Int,)) precompile(show, (Float64,)) @@ -286,7 +286,7 @@ precompile(split, (ASCIIString,)) precompile(split, (ASCIIString, ASCIIString, Int, Bool)) precompile(split, (ASCIIString, Regex, Int, Bool)) precompile(print_joined, (IOStream, Array{String,1}, ASCIIString)) -precompile(begins_with, (ASCIIString, ASCIIString)) +precompile(beginswith, (ASCIIString, ASCIIString)) precompile(resolve_globals, (Symbol, Module, Module, Vector{Any}, Vector{Any})) precompile(resolve_globals, (SymbolNode, Module, Module, Vector{Any}, Vector{Any})) precompile(BitArray, (Int,)) diff --git a/base/version.jl b/base/version.jl index ec60646e6a8f8..5fe6366e64ae9 100644 --- a/base/version.jl +++ b/base/version.jl @@ -75,7 +75,7 @@ function split_idents(s::String) idents = split(s, '.') ntuple(length(idents)) do i ident = idents[i] - ismatch(r"^\d+$", ident) ? parse_int(ident) : ident + ismatch(r"^\d+$", ident) ? parseint(ident) : ident end end diff --git a/doc/helpdb.jl b/doc/helpdb.jl index d6f0a9439a3d4..243b4ec94df11 100644 --- a/doc/helpdb.jl +++ b/doc/helpdb.jl @@ -1007,13 +1007,13 @@ "), -("Strings","Base","begins_with","begins_with(string, prefix) +("Strings","Base","beginswith","beginswith(string, prefix) Returns \"true\" if \"string\" starts with \"prefix\". "), -("Strings","Base","ends_with","ends_with(string, suffix) +("Strings","Base","endswith","endswith(string, suffix) Returns \"true\" if \"string\" ends with \"suffix\". @@ -2605,35 +2605,14 @@ "), -("Data Formats","Base","parse_int","parse_int(type, str[, base]) +("Data Formats","Base","parseint","parseint([type], str[, base]) Parse a string as an integer in the given base (default 10), - yielding a number of the specified type. + yielding a number of the specified type (default \"Int\"). "), -("Data Formats","Base","parse_bin","parse_bin(type, str) - - Parse a string as an integer in base 2, yielding a number of the - specified type. - -"), - -("Data Formats","Base","parse_oct","parse_oct(type, str) - - Parse a string as an integer in base 8, yielding a number of the - specified type. - -"), - -("Data Formats","Base","parse_hex","parse_hex(type, str) - - Parse a string as an integer in base 16, yielding a number of the - specified type. - -"), - -("Data Formats","Base","parse_float","parse_float(type, str) +("Data Formats","Base","parsefloat","parsefloat([type], str) Parse a string as a decimal floating point number, yielding a number of the specified type. diff --git a/doc/manual/functions.rst b/doc/manual/functions.rst index d67fc7551347d..57a0f1e3393d8 100644 --- a/doc/manual/functions.rst +++ b/doc/manual/functions.rst @@ -356,11 +356,11 @@ Optional Arguments In many cases, function arguments have sensible default values and therefore might not need to be passed explicitly in every call. For example, the -library function ``parse_int(num,base)`` interprets a string as a number +library function ``parseint(num,base)`` interprets a string as a number in some base. The ``base`` argument defaults to ``10``. This behavior can be expressed concisely as:: - function parse_int(num, base=10) + function parseint(num, base=10) ### end @@ -368,13 +368,13 @@ With this definition, the function can be called with either one or two arguments, and ``10`` is automatically passed when a second argument is not specified:: - julia> parse_int("12",10) + julia> parseint("12",10) 12 - julia> parse_int("12",3) + julia> parseint("12",3) 5 - julia> parse_int("12") + julia> parseint("12") 12 Optional arguments are actually just a convenient syntax for writing diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index cdb9d7f34e922..fdeddc27f3907 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -660,11 +660,11 @@ Strings Return ``string`` with any trailing whitespace removed. If a string ``chars`` is provided, instead remove characters contained in that string. -.. function:: begins_with(string, prefix) +.. function:: beginswith(string, prefix) Returns ``true`` if ``string`` starts with ``prefix``. -.. function:: ends_with(string, suffix) +.. function:: endswith(string, suffix) Returns ``true`` if ``string`` ends with ``suffix``. @@ -1688,23 +1688,11 @@ Data Formats A string giving the literal bit representation of a number. -.. function:: parse_int(type, str, [base]) +.. function:: parseint([type], str, [base]) - Parse a string as an integer in the given base (default 10), yielding a number of the specified type. + Parse a string as an integer in the given base (default 10), yielding a number of the specified type (default ``Int``). -.. function:: parse_bin(type, str) - - Parse a string as an integer in base 2, yielding a number of the specified type. - -.. function:: parse_oct(type, str) - - Parse a string as an integer in base 8, yielding a number of the specified type. - -.. function:: parse_hex(type, str) - - Parse a string as an integer in base 16, yielding a number of the specified type. - -.. function:: parse_float(type, str) +.. function:: parsefloat([type], str) Parse a string as a decimal floating point number, yielding a number of the specified type. diff --git a/test/perf/perf.jl b/test/perf/perf.jl index 67d7f61b1af66..5ece28c3f8113 100644 --- a/test/perf/perf.jl +++ b/test/perf/perf.jl @@ -29,7 +29,7 @@ function parseintperf(t) for i=1:t n = rand(Uint32) s = hex(n) - m = uint32(parse_hex(s)) + m = uint32(parseint(s,16)) end @test m == n return n diff --git a/test/perf2/go_benchmark.jl b/test/perf2/go_benchmark.jl index 14164edc53b1b..4c176a338ee5d 100644 --- a/test/perf2/go_benchmark.jl +++ b/test/perf2/go_benchmark.jl @@ -476,7 +476,7 @@ end function main(args) n = 10 if length(args) > 0 - n = parse_int(args[1]) + n = parseint(args[1]) end @time benchmark(n) end diff --git a/test/strings.jl b/test/strings.jl index 2318b5b89e41c..11a28ba453cb9 100644 --- a/test/strings.jl +++ b/test/strings.jl @@ -133,86 +133,90 @@ end @test "\x0F" == unescape_string("\\x0F") # integer parsing -@test is(parse_int(Int32,"0",36),int32(0)) -@test is(parse_int(Int32,"1",36),int32(1)) -@test is(parse_int(Int32,"9",36),int32(9)) -@test is(parse_int(Int32,"A",36),int32(10)) -@test is(parse_int(Int32,"a",36),int32(10)) -@test is(parse_int(Int32,"B",36),int32(11)) -@test is(parse_int(Int32,"b",36),int32(11)) -@test is(parse_int(Int32,"F",36),int32(15)) -@test is(parse_int(Int32,"f",36),int32(15)) -@test is(parse_int(Int32,"Z",36),int32(35)) -@test is(parse_int(Int32,"z",36),int32(35)) - -@test parse_int("0") == 0 -@test parse_int("-0") == 0 -@test parse_int("1") == 1 -@test parse_int("-1") == -1 -@test parse_int("9") == 9 -@test parse_int("-9") == -9 -@test parse_int("10") == 10 -@test parse_int("-10") == -10 -@test parse_int(Int64,"3830974272") == 3830974272 -@test parse_int(Int64,"-3830974272") == -3830974272 - -@test parse_bin("0") == 0 -@test parse_bin("-0") == 0 -@test parse_bin("1") == 1 -@test parse_bin("-1") == -1 -@test parse_bin("10") == 2 -@test parse_bin("-10") == -2 -@test parse_bin("11") == 3 -@test parse_bin("-11") == -3 -@test parse_bin("1111000011110000111100001111") == 252645135 -@test parse_bin("-1111000011110000111100001111") == -252645135 - -@test parse_oct("0") == 0 -@test parse_oct("-0") == 0 -@test parse_oct("1") == 1 -@test parse_oct("-1") == -1 -@test parse_oct("7") == 7 -@test parse_oct("-7") == -7 -@test parse_oct("10") == 8 -@test parse_oct("-10") == -8 -@test parse_oct("11") == 9 -@test parse_oct("-11") == -9 -@test parse_oct("72") == 58 -@test parse_oct("-72") == -58 -@test parse_oct("3172207320") == 434704080 -@test parse_oct("-3172207320") == -434704080 - -@test parse_hex("0") == 0 -@test parse_hex("-0") == 0 -@test parse_hex("1") == 1 -@test parse_hex("-1") == -1 -@test parse_hex("9") == 9 -@test parse_hex("-9") == -9 -@test parse_hex("a") == 10 -@test parse_hex("-a") == -10 -@test parse_hex("f") == 15 -@test parse_hex("-f") == -15 -@test parse_hex("10") == 16 -@test parse_hex("-10") == -16 -@test parse_hex("0BADF00D") == 195948557 -@test parse_hex("-0BADF00D") == -195948557 -@test parse_int(Int64,"BADCAB1E",16) == 3135023902 -@test parse_int(Int64,"-BADCAB1E",16) == -3135023902 -@test parse_int(Int64,"CafeBabe",16) == 3405691582 -@test parse_int(Int64,"-CafeBabe",16) == -3405691582 -@test parse_int(Int64,"DeadBeef",16) == 3735928559 -@test parse_int(Int64,"-DeadBeef",16) == -3735928559 - -@test parse_int("2\n") == 2 -@test parse_int(" 2 \n ") == 2 -@test parse_int(" 2 ") == 2 -@test parse_int("2 ") == 2 -@test parse_int(" 2") == 2 -@test parse_int("+2\n") == 2 -@test parse_int("-2") == -2 -@test_fails parse_int(" 2 \n 0") -@test_fails parse_int("2x") -@test_fails parse_int("-") +@test is(parseint(Int32,"0",36),int32(0)) +@test is(parseint(Int32,"1",36),int32(1)) +@test is(parseint(Int32,"9",36),int32(9)) +@test is(parseint(Int32,"A",36),int32(10)) +@test is(parseint(Int32,"a",36),int32(10)) +@test is(parseint(Int32,"B",36),int32(11)) +@test is(parseint(Int32,"b",36),int32(11)) +@test is(parseint(Int32,"F",36),int32(15)) +@test is(parseint(Int32,"f",36),int32(15)) +@test is(parseint(Int32,"Z",36),int32(35)) +@test is(parseint(Int32,"z",36),int32(35)) + +@test parseint("0") == 0 +@test parseint("-0") == 0 +@test parseint("1") == 1 +@test parseint("-1") == -1 +@test parseint("9") == 9 +@test parseint("-9") == -9 +@test parseint("10") == 10 +@test parseint("-10") == -10 +@test parseint(Int64,"3830974272") == 3830974272 +@test parseint(Int64,"-3830974272") == -3830974272 + +parsebin(s) = parseint(s,2) +parseoct(s) = parseint(s,8) +parsehex(s) = parseint(s,16) + +@test parsebin("0") == 0 +@test parsebin("-0") == 0 +@test parsebin("1") == 1 +@test parsebin("-1") == -1 +@test parsebin("10") == 2 +@test parsebin("-10") == -2 +@test parsebin("11") == 3 +@test parsebin("-11") == -3 +@test parsebin("1111000011110000111100001111") == 252645135 +@test parsebin("-1111000011110000111100001111") == -252645135 + +@test parseoct("0") == 0 +@test parseoct("-0") == 0 +@test parseoct("1") == 1 +@test parseoct("-1") == -1 +@test parseoct("7") == 7 +@test parseoct("-7") == -7 +@test parseoct("10") == 8 +@test parseoct("-10") == -8 +@test parseoct("11") == 9 +@test parseoct("-11") == -9 +@test parseoct("72") == 58 +@test parseoct("-72") == -58 +@test parseoct("3172207320") == 434704080 +@test parseoct("-3172207320") == -434704080 + +@test parsehex("0") == 0 +@test parsehex("-0") == 0 +@test parsehex("1") == 1 +@test parsehex("-1") == -1 +@test parsehex("9") == 9 +@test parsehex("-9") == -9 +@test parsehex("a") == 10 +@test parsehex("-a") == -10 +@test parsehex("f") == 15 +@test parsehex("-f") == -15 +@test parsehex("10") == 16 +@test parsehex("-10") == -16 +@test parsehex("0BADF00D") == 195948557 +@test parsehex("-0BADF00D") == -195948557 +@test parseint(Int64,"BADCAB1E",16) == 3135023902 +@test parseint(Int64,"-BADCAB1E",16) == -3135023902 +@test parseint(Int64,"CafeBabe",16) == 3405691582 +@test parseint(Int64,"-CafeBabe",16) == -3405691582 +@test parseint(Int64,"DeadBeef",16) == 3735928559 +@test parseint(Int64,"-DeadBeef",16) == -3735928559 + +@test parseint("2\n") == 2 +@test parseint(" 2 \n ") == 2 +@test parseint(" 2 ") == 2 +@test parseint("2 ") == 2 +@test parseint(" 2") == 2 +@test parseint("+2\n") == 2 +@test parseint("-2") == -2 +@test_fails parseint(" 2 \n 0") +@test_fails parseint("2x") +@test_fails parseint("-") # string manipulation @test strip("\t hi \n") == "hi" @@ -454,17 +458,17 @@ end @test replace("abcd", r"b?c?", "^") == "^a^d^" @test replace("abcd", r"[bc]?", "^") == "^a^^d^" -# {begins,ends}_with -@test begins_with("abcd", 'a') -@test begins_with("abcd", "a") -@test begins_with("abcd", "ab") -@test !begins_with("ab", "abcd") -@test !begins_with("abcd", "bc") -@test ends_with("abcd", 'd') -@test ends_with("abcd", "d") -@test ends_with("abcd", "cd") -@test !ends_with("abcd", "dc") -@test !ends_with("cd", "abcd") +# {begins,ends}with +@test beginswith("abcd", 'a') +@test beginswith("abcd", "a") +@test beginswith("abcd", "ab") +@test !beginswith("ab", "abcd") +@test !beginswith("abcd", "bc") +@test endswith("abcd", 'd') +@test endswith("abcd", "d") +@test endswith("abcd", "cd") +@test !endswith("abcd", "dc") +@test !endswith("cd", "abcd") # RepStrings and SubStrings u8str2 = u8str^2 diff --git a/test/test_sourcepath.jl b/test/test_sourcepath.jl index 89c553f5043e8..d0436b36ca064 100644 --- a/test/test_sourcepath.jl +++ b/test/test_sourcepath.jl @@ -1,4 +1,4 @@ # source path in tasks path = Base.source_path() -@test ends_with(path, joinpath("test","test_sourcepath.jl")) +@test endswith(path, joinpath("test","test_sourcepath.jl")) @test yieldto(@task Base.source_path()) == path