Browse Source

Merge pull request #2440 from jon-lipstate/doc_fixed

resolve doc-test issues
Jeroen van Rijn 2 years ago
parent
commit
14736c2a8b
3 changed files with 85 additions and 34 deletions
  1. 2 0
      .gitignore
  2. 5 7
      core/strconv/decimal/decimal.odin
  3. 78 27
      core/strconv/strconv.odin

+ 2 - 0
.gitignore

@@ -22,6 +22,8 @@ bld/
 [Oo]bj/
 [Oo]bj/
 [Ll]og/
 [Ll]og/
 ![Cc]ore/[Ll]og/
 ![Cc]ore/[Ll]og/
+tests/documentation/verify/
+tests/documentation/all.odin-doc
 # Visual Studio 2015 cache/options directory
 # Visual Studio 2015 cache/options directory
 .vs/
 .vs/
 # Visual Studio Code options directory
 # Visual Studio Code options directory

+ 5 - 7
core/strconv/decimal/decimal.odin

@@ -500,9 +500,8 @@ Rounds down the decimal value to the specified number of decimal places
 Example:
 Example:
 
 
 	import "core:fmt"
 	import "core:fmt"
-	import "core:strconv"
-
-	strconv_round_down_example :: proc {
+	import "core:strconv/decimal"
+	round_down_example :: proc() {
 		d: decimal.Decimal
 		d: decimal.Decimal
 		str := [64]u8{}
 		str := [64]u8{}
 		ok := decimal.set(&d, "123.456")
 		ok := decimal.set(&d, "123.456")
@@ -533,10 +532,9 @@ WARNING: There are no guarantees about overflow.
 Example:
 Example:
 
 
 	import "core:fmt"
 	import "core:fmt"
-	import "core:strconv"
-
-	strconv_rounded_integer_example :: proc {
-    	d: decimal.Decimal
+	import "core:strconv/decimal"
+	rounded_integer_example :: proc() {
+		d: decimal.Decimal
 		ok := decimal.set(&d, "123.456")
 		ok := decimal.set(&d, "123.456")
 		fmt.println(decimal.rounded_integer(&d))
 		fmt.println(decimal.rounded_integer(&d))
 	}
 	}

+ 78 - 27
core/strconv/strconv.odin

@@ -54,6 +54,8 @@ Parses an integer value from the input string in the given base, without a prefi
 
 
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	parse_i64_of_base_example :: proc() {
 	parse_i64_of_base_example :: proc() {
 		n, ok := strconv.parse_i64_of_base("-1234e3", 10)
 		n, ok := strconv.parse_i64_of_base("-1234e3", 10)
 		fmt.println(n, ok)
 		fmt.println(n, ok)
@@ -121,6 +123,8 @@ Parses an integer value from the input string in base 10, unless there's a prefi
 
 
 Example:
 Example:
 	
 	
+	import "core:fmt"
+	import "core:strconv"
 	parse_i64_maybe_prefixed_example :: proc() {
 	parse_i64_maybe_prefixed_example :: proc() {
 		n, ok := strconv.parse_i64_maybe_prefixed("1234")
 		n, ok := strconv.parse_i64_maybe_prefixed("1234")
 		fmt.println(n,ok)
 		fmt.println(n,ok)
@@ -131,8 +135,8 @@ Example:
 	
 	
 Output:
 Output:
 
 
-	1234 true  
-	61166 true  
+	1234 true
+	61166 true
 
 
 **Returns**  
 **Returns**  
 - value: The parsed integer value
 - value: The parsed integer value
@@ -204,6 +208,8 @@ Parses an unsigned 64-bit integer value from the input string without a prefix,
 
 
 Example:
 Example:
 	
 	
+	import "core:fmt"
+	import "core:strconv"
 	parse_u64_of_base_example :: proc() {
 	parse_u64_of_base_example :: proc() {
 		n, ok := strconv.parse_u64_of_base("1234e3", 10)
 		n, ok := strconv.parse_u64_of_base("1234e3", 10)
 		fmt.println(n,ok)
 		fmt.println(n,ok)
@@ -214,8 +220,8 @@ Example:
 	
 	
 Output:
 Output:
 
 
-	1234 false  
-	90672878 true  
+	1234 false
+	90672878 true
 
 
 **Returns**  
 **Returns**  
 - value: The parsed uint64 value
 - value: The parsed uint64 value
@@ -264,6 +270,8 @@ Parses an unsigned 64-bit integer value from the input string, using the specifi
 
 
 Example:
 Example:
 	
 	
+	import "core:fmt"
+	import "core:strconv"
 	parse_u64_maybe_prefixed_example :: proc() {
 	parse_u64_maybe_prefixed_example :: proc() {
 		n, ok := strconv.parse_u64_maybe_prefixed("1234")
 		n, ok := strconv.parse_u64_maybe_prefixed("1234")
 		fmt.println(n,ok)
 		fmt.println(n,ok)
@@ -274,8 +282,8 @@ Example:
 	
 	
 Output:
 Output:
 
 
-	1234 true  
-	238 true  
+	1234 true
+	238 true
 
 
 **Returns**  
 **Returns**  
 - value: The parsed uint64 value
 - value: The parsed uint64 value
@@ -336,6 +344,8 @@ Parses a signed integer value from the input string, using the specified base or
 
 
 Example:
 Example:
 	
 	
+	import "core:fmt"
+	import "core:strconv"
 	parse_int_example :: proc() {
 	parse_int_example :: proc() {
 		n, ok := strconv.parse_int("1234") // without prefix, inferred base 10
 		n, ok := strconv.parse_int("1234") // without prefix, inferred base 10
 		fmt.println(n,ok)
 		fmt.println(n,ok)
@@ -349,9 +359,9 @@ Example:
 	
 	
 Output:
 Output:
 
 
-	1234 true  
-	65535 true  
-	65535 true  
+	1234 true
+	65535 true
+	65535 true
 
 
 **Returns**  
 **Returns**  
 - value: The parsed int value
 - value: The parsed int value
@@ -377,6 +387,8 @@ Parses an unsigned integer value from the input string, using the specified base
 
 
 Example:
 Example:
 	
 	
+	import "core:fmt"
+	import "core:strconv"
 	parse_uint_example :: proc() {
 	parse_uint_example :: proc() {
 		n, ok := strconv.parse_uint("1234") // without prefix, inferred base 10
 		n, ok := strconv.parse_uint("1234") // without prefix, inferred base 10
 		fmt.println(n,ok)
 		fmt.println(n,ok)
@@ -390,9 +402,9 @@ Example:
 	
 	
 Output:
 Output:
 
 
-	1234 true  
-	65535 true  
-	65535 true  
+	1234 true
+	65535 true
+	65535 true
 
 
 **Returns**  
 **Returns**  
 
 
@@ -418,6 +430,8 @@ Parses an integer value from a string in the given base, without any prefix
 
 
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	parse_i128_of_base_example :: proc() {
 	parse_i128_of_base_example :: proc() {
 		n, ok := strconv.parse_i128_of_base("-1234eeee", 10)
 		n, ok := strconv.parse_i128_of_base("-1234eeee", 10)
 		fmt.println(n,ok)
 		fmt.println(n,ok)
@@ -425,7 +439,7 @@ Example:
 	
 	
 Output:
 Output:
 
 
-	-1234 false  
+	-1234 false
 
 
 **Returns**  
 **Returns**  
 - value: The parsed i128 value
 - value: The parsed i128 value
@@ -483,6 +497,8 @@ Parses an integer value from a string in base 10, unless there's a prefix
 
 
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	parse_i128_maybe_prefixed_example :: proc() {
 	parse_i128_maybe_prefixed_example :: proc() {
 		n, ok := strconv.parse_i128_maybe_prefixed("1234")
 		n, ok := strconv.parse_i128_maybe_prefixed("1234")
 		fmt.println(n, ok)
 		fmt.println(n, ok)
@@ -493,8 +509,8 @@ Example:
 	
 	
 Output:
 Output:
 
 
-	1234 true  
-	61166 true  
+	1234 true
+	61166 true
 	
 	
 **Returns**  
 **Returns**  
 - value: The parsed i128 value
 - value: The parsed i128 value
@@ -565,6 +581,8 @@ Parses an unsigned integer value from a string in the given base, without any pr
 
 
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	parse_u128_of_base_example :: proc() {
 	parse_u128_of_base_example :: proc() {
 		n, ok := strconv.parse_u128_of_base("1234eeee", 10)
 		n, ok := strconv.parse_u128_of_base("1234eeee", 10)
 		fmt.println(n, ok)
 		fmt.println(n, ok)
@@ -622,6 +640,8 @@ Parses an unsigned integer value from a string in base 10, unless there's a pref
 
 
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	parse_u128_maybe_prefixed_example :: proc() {
 	parse_u128_maybe_prefixed_example :: proc() {
 		n, ok := strconv.parse_u128_maybe_prefixed("1234")
 		n, ok := strconv.parse_u128_maybe_prefixed("1234")
 		fmt.println(n, ok)
 		fmt.println(n, ok)
@@ -703,6 +723,8 @@ Parses a 32-bit floating point number from a string
 
 
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	parse_f32_example :: proc() {
 	parse_f32_example :: proc() {
 		n, ok := strconv.parse_f32("1234eee")
 		n, ok := strconv.parse_f32("1234eee")
 		fmt.println(n, ok)
 		fmt.println(n, ok)
@@ -734,6 +756,8 @@ Parses a 64-bit floating point number from a string
 
 
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	parse_f64_example :: proc() {
 	parse_f64_example :: proc() {
 		n, ok := strconv.parse_f64("1234eee")
 		n, ok := strconv.parse_f64("1234eee")
 		fmt.println(n, ok)
 		fmt.println(n, ok)
@@ -768,6 +792,8 @@ Parses a 32-bit floating point number from a string and returns the parsed numbe
 
 
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	parse_f32_prefix_example :: proc() {
 	parse_f32_prefix_example :: proc() {
 		n, _, ok := strconv.parse_f32_prefix("1234eee")
 		n, _, ok := strconv.parse_f32_prefix("1234eee")
 		fmt.println(n, ok)
 		fmt.println(n, ok)
@@ -801,7 +827,9 @@ Parses a 64-bit floating point number from a string and returns the parsed numbe
 
 
 Example:
 Example:
 
 
-    parse_f64_prefix_example :: proc() {
+	import "core:fmt"
+	import "core:strconv"
+	parse_f64_prefix_example :: proc() {
 		n, _, ok := strconv.parse_f64_prefix("12.34eee")
 		n, _, ok := strconv.parse_f64_prefix("12.34eee")
 		fmt.println(n, ok)
 		fmt.println(n, ok)
 
 
@@ -1105,8 +1133,10 @@ Appends a boolean value as a string to the given buffer
 
 
 Example:
 Example:
 
 
-    append_bool_example :: proc() {
-		buf: [4]byte
+	import "core:fmt"
+	import "core:strconv"
+	append_bool_example :: proc() {
+		buf: [6]byte
 		result := strconv.append_bool(buf[:], true)
 		result := strconv.append_bool(buf[:], true)
 		fmt.println(result, buf)
 		fmt.println(result, buf)
 	}
 	}
@@ -1137,7 +1167,9 @@ Appends an unsigned integer value as a string to the given buffer with the speci
 
 
 Example:
 Example:
 
 
-    append_uint_example :: proc() {
+	import "core:fmt"
+	import "core:strconv"
+	append_uint_example :: proc() {
 		buf: [4]byte
 		buf: [4]byte
 		result := strconv.append_uint(buf[:], 42, 16)
 		result := strconv.append_uint(buf[:], 42, 16)
 		fmt.println(result, buf)
 		fmt.println(result, buf)
@@ -1163,7 +1195,9 @@ Appends a signed integer value as a string to the given buffer with the specifie
 
 
 Example:
 Example:
 
 
-    append_int_example :: proc() {
+	import "core:fmt"
+	import "core:strconv"
+	append_int_example :: proc() {
 		buf: [4]byte
 		buf: [4]byte
 		result := strconv.append_int(buf[:], -42, 10)
 		result := strconv.append_int(buf[:], -42, 10)
 		fmt.println(result, buf)
 		fmt.println(result, buf)
@@ -1188,7 +1222,9 @@ Converts an integer value to a string and stores it in the given buffer
 
 
 Example:
 Example:
 
 
-    itoa_example :: proc() {
+	import "core:fmt"
+	import "core:strconv"
+	itoa_example :: proc() {
 		buf: [4]byte
 		buf: [4]byte
 		result := strconv.itoa(buf[:], 42)
 		result := strconv.itoa(buf[:], 42)
 		fmt.println(result, buf) // "42"
 		fmt.println(result, buf) // "42"
@@ -1212,6 +1248,8 @@ Converts a string to an integer value
 
 
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	atoi_example :: proc() {
 	atoi_example :: proc() {
 		fmt.println(strconv.atoi("42"))
 		fmt.println(strconv.atoi("42"))
 	}
 	}
@@ -1235,6 +1273,8 @@ Converts a string to a float64 value
 
 
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	atof_example :: proc() {
 	atof_example :: proc() {
 		fmt.println(strconv.atof("3.14"))
 		fmt.println(strconv.atof("3.14"))
 	}
 	}
@@ -1264,6 +1304,8 @@ Appends a float64 value as a string to the given buffer with the specified forma
 
 
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	append_float_example :: proc() {
 	append_float_example :: proc() {
 		buf: [8]byte
 		buf: [8]byte
 		result := strconv.append_float(buf[:], 3.14159, 'f', 2, 64)
 		result := strconv.append_float(buf[:], 3.14159, 'f', 2, 64)
@@ -1287,8 +1329,12 @@ Appends a quoted string representation of the input string to a given byte slice
 - buf: The byte slice to which the quoted string will be appended
 - buf: The byte slice to which the quoted string will be appended
 - str: The input string to be quoted
 - str: The input string to be quoted
 
 
+!! ISSUE !! NOT EXPECTED -- "\"hello\"" was expected  
+
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	quote_example :: proc() {
 	quote_example :: proc() {
 		buf: [20]byte
 		buf: [20]byte
 		result := strconv.quote(buf[:], "hello")
 		result := strconv.quote(buf[:], "hello")
@@ -1297,8 +1343,7 @@ Example:
 
 
 Output:
 Output:
 
 
-	!! ISSUE !! NOT EXPECTED -- "\"hello\"" was expected  
-	"'h''e''l''l''o'" [34, 39, 104, 39, 39, 101, 39, 39, 108, 39, 39, 108, 39, 39, 111, 39, 34, 0, 0, 0]  
+	"'h''e''l''l''o'" [34, 39, 104, 39, 39, 101, 39, 39, 108, 39, 39, 108, 39, 39, 111, 39, 34, 0, 0, 0]
 
 
 **Returns**  
 **Returns**  
 - The resulting string after appending the quoted string representation
 - The resulting string after appending the quoted string representation
@@ -1349,6 +1394,8 @@ Appends a quoted rune representation of the input rune to a given byte slice and
 
 
 Example:
 Example:
 
 
+	import "core:fmt"
+	import "core:strconv"
 	quote_rune_example :: proc() {
 	quote_rune_example :: proc() {
 		buf: [4]byte
 		buf: [4]byte
 		result := strconv.quote_rune(buf[:], 'A')
 		result := strconv.quote_rune(buf[:], 'A')
@@ -1426,6 +1473,8 @@ Unquotes a single character from the input string, considering the given quote c
 
 
 Example:  
 Example:  
 
 
+	import "core:fmt"
+	import "core:strconv"
 	unquote_char_example :: proc() {
 	unquote_char_example :: proc() {
 		src:="\'The\' raven"
 		src:="\'The\' raven"
 		r, multiple_bytes, tail_string, success  := strconv.unquote_char(src,'\'')
 		r, multiple_bytes, tail_string, success  := strconv.unquote_char(src,'\'')
@@ -1549,18 +1598,20 @@ WARNING: This procedure gives unexpected results if the quotes are not the first
 
 
 Example:  
 Example:  
 
 
+	import "core:fmt"
+	import "core:strconv"
 	unquote_string_example :: proc() {
 	unquote_string_example :: proc() {
 		src:="\"The raven Huginn is black.\""
 		src:="\"The raven Huginn is black.\""
 		s, allocated, ok := strconv.unquote_string(src)
 		s, allocated, ok := strconv.unquote_string(src)
 		fmt.println(src)
 		fmt.println(src)
 		fmt.printf("Unquoted: <%s>, alloc:%v, ok:%v\n\n", s, allocated, ok)
 		fmt.printf("Unquoted: <%s>, alloc:%v, ok:%v\n\n", s, allocated, ok)
-		
+
 		src="\'The raven Huginn\' is black."
 		src="\'The raven Huginn\' is black."
 		s, allocated, ok = strconv.unquote_string(src)
 		s, allocated, ok = strconv.unquote_string(src)
 		fmt.println(src)
 		fmt.println(src)
 		fmt.printf("Unquoted: <%s>, alloc:%v, ok:%v\n\n", s, allocated, ok)
 		fmt.printf("Unquoted: <%s>, alloc:%v, ok:%v\n\n", s, allocated, ok)
 
 
-		src="The raven \"Huginn\" is black."
+		src="The raven \'Huginn\' is black."
 		s, allocated, ok = strconv.unquote_string(src) // Will produce undesireable results
 		s, allocated, ok = strconv.unquote_string(src) // Will produce undesireable results
 		fmt.println(src)
 		fmt.println(src)
 		fmt.printf("Unquoted: <%s>, alloc:%v, ok:%v\n", s, allocated, ok) 
 		fmt.printf("Unquoted: <%s>, alloc:%v, ok:%v\n", s, allocated, ok) 
@@ -1574,8 +1625,8 @@ Output:
 	'The raven Huginn' is black.
 	'The raven Huginn' is black.
 	Unquoted: <The raven Huginn' is black>, alloc:false, ok:true
 	Unquoted: <The raven Huginn' is black>, alloc:false, ok:true
 
 
-	Source: The raven `Huginn` is black.
-	Unquoted: <he raven `Huginn` is black>, alloc:false, ok:true
+	The raven 'Huginn' is black.
+	Unquoted: <he raven 'Huginn' is black>, alloc:false, ok:true
 
 
 **Returns**  
 **Returns**  
 - res: The resulting unquoted string
 - res: The resulting unquoted string