Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  testStringIsArrayIndex.cpp

  Sprache: C
 

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=8 sts=2 et sw=2 tw=80:
 */

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#include <string>

#include "jsfriendapi.h"

#include "jsapi-tests/tests.h"

static const struct TestTuple {
  /* The string being tested. */
  const char16_t* string;
  /* The number of characters from the string to use. */
  size_t length;
  /* Whether this string is an index. */
  bool isindex;
  /* If it's an index, what index it is.  Ignored if not an index. */
  uint32_t index;

  constexpr TestTuple(const char16_t* string, bool isindex, uint32_t index)
      : TestTuple(string, std::char_traits<char16_t>::length(string), isindex,
                  index) {}

  constexpr TestTuple(const char16_t* string, size_t length, bool isindex,
                      uint32_t index)
      : string(string), length(length), isindex(isindex), index(index) {}
} tests[] = {
    {u"0"true0},
    {u"1"true1},
    {u"2"true2},
    {u"9"true9},
    {u"10"true10},
    {u"15"true15},
    {u"16"true16},
    {u"17"true17},
    {u"99"true99},
    {u"100"true100},
    {u"255"true255},
    {u"256"true256},
    {u"257"true257},
    {u"999"true999},
    {u"1000"true1000},
    {u"4095"true4095},
    {u"4096"true4096},
    {u"9999"true9999},
    {u"1073741823"true1073741823},
    {u"1073741824"true1073741824},
    {u"1073741825"true1073741825},
    {u"2147483647"true2147483647},
    {u"2147483648"true2147483648u},
    {u"2147483649"true2147483649u},
    {u"4294967294"true4294967294u},
    {u"4294967295"false,
     0},  // Not an array index because need to be able to represent length
    {u"-1"false0},
    {u"abc"false0},
    {u" 0"false0},
    {u"0 "false0},
    // Tests to make sure the passed-in length is taken into account
    {u"0 "1true0},
    {u"123abc"3true123},
    {u"123abc"2true12},
};

BEGIN_TEST(testStringIsArrayIndex) {
  for (const auto& test : tests) {
    uint32_t index;
    bool isindex = js::StringIsArrayIndex(test.string, test.length, &index);
    CHECK_EQUAL(isindex, test.isindex);
    if (isindex) {
      CHECK_EQUAL(index, test.index);
    }
  }

  return true;
}
END_TEST(testStringIsArrayIndex)

Messung V0.5 in Prozent
C=90 H=97 G=93

¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik