Project

General

Profile

Bug #15449 ยป range-case-cover-string.patch

jeremyevans0 (Jeremy Evans), 07/29/2019 11:32 PM

View differences:

range.c
1348 1348
    return rb_exec_recursive(inspect_range, range, 0);
1349 1349
}
1350 1350

  
1351
static VALUE range_include_internal(VALUE range, VALUE val);
1351
static VALUE range_include_internal(VALUE range, VALUE val, int string_use_cover);
1352 1352

  
1353 1353
/*
1354 1354
 *  call-seq:
......
1372 1372
static VALUE
1373 1373
range_eqq(VALUE range, VALUE val)
1374 1374
{
1375
    VALUE ret = range_include_internal(range, val);
1375
    VALUE ret = range_include_internal(range, val, 1);
1376 1376
    if (ret != Qundef) return ret;
1377 1377
    return r_cover_p(range, RANGE_BEG(range), RANGE_END(range), val);
1378 1378
}
......
1395 1395
static VALUE
1396 1396
range_include(VALUE range, VALUE val)
1397 1397
{
1398
    VALUE ret = range_include_internal(range, val);
1398
    VALUE ret = range_include_internal(range, val, 0);
1399 1399
    if (ret != Qundef) return ret;
1400 1400
    return rb_call_super(1, &val);
1401 1401
}
1402 1402

  
1403 1403
static VALUE
1404
range_include_internal(VALUE range, VALUE val)
1404
range_include_internal(VALUE range, VALUE val, int string_use_cover)
1405 1405
{
1406 1406
    VALUE beg = RANGE_BEG(range);
1407 1407
    VALUE end = RANGE_END(range);
......
1413 1413
	!NIL_P(rb_check_to_integer(end, "to_int"))) {
1414 1414
	return r_cover_p(range, beg, end, val);
1415 1415
    }
1416
    else if (RB_TYPE_P(beg, T_STRING)) {
1417
	if (RB_TYPE_P(end, T_STRING)) {
1418
	    VALUE rb_str_include_range_p(VALUE beg, VALUE end, VALUE val, VALUE exclusive);
1419
	    return rb_str_include_range_p(beg, end, val, RANGE_EXCL(range));
1420
	}
1416
    else if (RB_TYPE_P(beg, T_STRING) || RB_TYPE_P(end, T_STRING)) {
1417
        if (RB_TYPE_P(beg, T_STRING) && RB_TYPE_P(end, T_STRING)) {
1418
            if (string_use_cover) {
1419
                return r_cover_p(range, beg, end, val);
1420
            }
1421
            else {
1422
                VALUE rb_str_include_range_p(VALUE beg, VALUE end, VALUE val, VALUE exclusive);
1423
                return rb_str_include_range_p(beg, end, val, RANGE_EXCL(range));
1424
            }
1425
        }
1421 1426
        else if (NIL_P(beg)) {
1422 1427
	    VALUE r = rb_funcall(val, id_cmp, 1, end);
1423 1428
	    if (NIL_P(r)) return Qfalse;
test/ruby/test_range.rb
507 507
    assert_not_operator(5..nil, :===, 0)
508 508
  end
509 509

  
510
  def test_eqq_string
511
    assert_operator('A'..'Z', :===, 'ANA')
512
    assert_not_operator('A'..'Z', :===, 'ana')
513
    assert_operator('A'.., :===, 'ANA')
514
    assert_operator(..'Z', :===, 'ANA')
515
    assert_operator(nil..nil, :===, 'ANA')
516
  end
517

  
510 518
  def test_eqq_time
511 519
    bug11113 = '[ruby-core:69052] [Bug #11113]'
512 520
    t = Time.now
513
-