mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
parent
870350253e
commit
b8681c2e37
4 changed files with 3 additions and 37 deletions
|
@ -1065,35 +1065,6 @@ named_captures(VALUE self, VALUE source) {
|
|||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* call-seq:
|
||||
* Debug::integer_parse(source) -> [Integer, String]
|
||||
*
|
||||
* Parses the given source string and returns the integer it represents, as well
|
||||
* as a decimal string representation.
|
||||
*/
|
||||
static VALUE
|
||||
integer_parse(VALUE self, VALUE source) {
|
||||
const uint8_t *start = (const uint8_t *) RSTRING_PTR(source);
|
||||
size_t length = RSTRING_LEN(source);
|
||||
|
||||
pm_integer_t integer = { 0 };
|
||||
pm_integer_parse(&integer, PM_INTEGER_BASE_UNKNOWN, start, start + length);
|
||||
|
||||
pm_buffer_t buffer = { 0 };
|
||||
pm_integer_string(&buffer, &integer);
|
||||
|
||||
VALUE string = rb_str_new(pm_buffer_value(&buffer), pm_buffer_length(&buffer));
|
||||
pm_buffer_free(&buffer);
|
||||
|
||||
VALUE result = rb_ary_new_capa(2);
|
||||
rb_ary_push(result, pm_integer_new(&integer));
|
||||
rb_ary_push(result, string);
|
||||
pm_integer_free(&integer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* call-seq:
|
||||
* Debug::memsize(source) -> { length: xx, memsize: xx, node_count: xx }
|
||||
|
@ -1376,7 +1347,6 @@ Init_prism(void) {
|
|||
// internal tasks. We expose these to make them easier to test.
|
||||
VALUE rb_cPrismDebug = rb_define_module_under(rb_cPrism, "Debug");
|
||||
rb_define_singleton_method(rb_cPrismDebug, "named_captures", named_captures, 1);
|
||||
rb_define_singleton_method(rb_cPrismDebug, "integer_parse", integer_parse, 1);
|
||||
rb_define_singleton_method(rb_cPrismDebug, "memsize", memsize, 1);
|
||||
rb_define_singleton_method(rb_cPrismDebug, "profile_file", profile_file, 1);
|
||||
rb_define_singleton_method(rb_cPrismDebug, "format_errors", format_errors, 2);
|
||||
|
|
|
@ -471,7 +471,7 @@ pm_integer_parse_big(pm_integer_t *integer, uint32_t multiplier, const uint8_t *
|
|||
* has already been validated, as internal validation checks are not performed
|
||||
* here.
|
||||
*/
|
||||
PRISM_EXPORTED_FUNCTION void
|
||||
void
|
||||
pm_integer_parse(pm_integer_t *integer, pm_integer_base_t base, const uint8_t *start, const uint8_t *end) {
|
||||
// Ignore unary +. Unary - is parsed differently and will not end up here.
|
||||
// Instead, it will modify the parsed integer later.
|
||||
|
|
|
@ -82,7 +82,7 @@ typedef enum {
|
|||
* @param start The start of the string.
|
||||
* @param end The end of the string.
|
||||
*/
|
||||
PRISM_EXPORTED_FUNCTION void pm_integer_parse(pm_integer_t *integer, pm_integer_base_t base, const uint8_t *start, const uint8_t *end);
|
||||
void pm_integer_parse(pm_integer_t *integer, pm_integer_base_t base, const uint8_t *start, const uint8_t *end);
|
||||
|
||||
/**
|
||||
* Return the memory size of the integer.
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
require_relative "test_helper"
|
||||
|
||||
return if Prism::BACKEND == :FFI
|
||||
|
||||
module Prism
|
||||
class IntegerParseTest < TestCase
|
||||
def test_integer_parse
|
||||
|
@ -37,9 +35,7 @@ module Prism
|
|||
private
|
||||
|
||||
def assert_integer_parse(expected, source = expected.to_s)
|
||||
integer, string = Debug.integer_parse(source)
|
||||
assert_equal expected, integer
|
||||
assert_equal expected.to_s, string
|
||||
assert_equal expected, Prism.parse(source).value.statements.body.first.value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue