Changeset 1207


Ignore:
Timestamp:
Oct 7, 2010, 5:25:31 AM (13 years ago)
Author:
Peter Johansson
Message:

new function 'diff' to compare two strings

Location:
trunk/test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Suite.cc

    r1182 r1207  
    193193    suite.add(check_total(stats, suite));
    194194    suite.add(check_comment_or_copy(stats, suite));
     195    return true;
     196  }
     197
     198
     199  bool diff(const std::string& a, const std::string& b)
     200  {
     201    if (a==b)
     202      return false;
     203
     204    std::istringstream ssa(a);
     205    std::istringstream ssb(b);
     206
     207    std::string linea;
     208    std::string lineb;
     209    while (ssa || ssb) {
     210      if (!ssa) {
     211        getline(ssb, lineb);
     212        std::cout << "+ " << lineb << "\n";
     213      }
     214      else if (!ssb) {
     215        getline(ssa, linea);
     216        std::cout << "- " << lineb << "\n";
     217      }
     218      else {
     219        getline(ssa, linea);
     220        getline(ssb, lineb);
     221        if (linea==lineb)
     222          std::cout << "  " << linea << "\n";
     223        else {
     224          std::cout << "- " << linea << "\n";
     225          std::cout << "+ " << lineb << "\n";
     226        }
     227      }
     228    }
    195229    return true;
    196230  }
  • trunk/test/Suite.h

    r1182 r1207  
    8282  bool consistent(const Stats&, test::Suite&);
    8383
     84  // return true if a and b are different
     85  // sends differences to cout
     86  bool diff(const std::string& a, const std::string& b);
     87
    8488  bool equal(const StatsCollection& a, const StatsCollection& b,
    8589             test::Suite& suite);
Note: See TracChangeset for help on using the changeset viewer.