<commit_before><!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  <link rel="stylesheet" href="mocha.css"/>
  <style>
  iframe { visibility: hidden; }
  </style>
  <title>p5 Reference Documentation Test</title>
</head>
<body>
  <!-- Required for browser reporter -->
  <div id="mocha"></div>

  <!-- mocha -->
  <script src="js/mocha.js" type="text/javascript" ></script>
  <script type="text/javascript" >
    // This will be overridden by mocha-helper if you run with grunt
    mocha.setup('tdd');
    mocha.reporter('html');
  </script>

  <!-- Include your assertion lib of choice -->
  <script src="js/chai.js" type="text/javascript" ></script>
  <script src="js/bind.js" type="text/javascript" ></script>
  <script src="js/sinon.js" type="text/javascript" ></script>
  <script src="js/testRender.js" type="text/javascript" ></script>
  <script type="text/javascript" >
    // Setup chai
    var expect = chai.expect;
    var assert = chai.assert;
  </script>

  <!-- Include anything you want to test -->
  <script src="../lib/p5.js" type="text/javascript" ></script>
  <script src="../lib/addons/p5.dom.js" type="text/javascript" ></script>
  <script src="../lib/addons/p5.sound.js" type="text/javascript" ></script>

  <script>
  var MS_TIMEOUT = 2000;

  // TODO: This code has basically been harvested from
  // https://github.com/processing/p5.js-website/blob/master/js/render.js.
  // Ideally we should factor out this common code into a shared place
  // where we're not duplicating code.
  function createExampleSketch(exampleCode, cb) {
    var runnable = exampleCode.replace(/^\s+|\s+$/g, '');

    return function( p ) {
      if (runnable.indexOf('setup()') === -1 &&
          runnable.indexOf('draw()') === -1){
        p.setup = function() {
          p.createCanvas(100, 100);
          p.background(200);
          with (p) {
            eval(runnable);
          }
        }
      } else {
        with (p) {
          eval(runnable);
        }

        var fxns = [
          'setup', 'draw', 'preload', 'mousePressed', 'mouseReleased', 
          'mouseMoved', 'mouseDragged', 'mouseClicked', 'mouseWheel', 
          'touchStarted', 'touchMoved', 'touchEnded', 
          'keyPressed', 'keyReleased', 'keyTyped'
        ];
        fxns.forEach(function(f) { 
          var ind = runnable.indexOf(f+'(');
          // this is a gross hack within a hacky script that
          // ensures the function names found are not substrings
          // proper use of regex would be preferable...
          if (ind !== -1 && runnable[ind+f.length] === '(' &&
              eval('typeof ' + f) !== 'undefined') {
            with (p) {
              p[f] = eval(f);
            }
          }
        });
        if (typeof p.setup === 'undefined') {
          p.setup = function() {
            p.createCanvas(100, 100);
            p.background(200);
          }
        }
      }

      if (cb) {
        cb(p);
      }
    };
  }

  function defineTest(info) {
    suite(info.name + " documentation", function() {
      var myp5, myp5Div;
      var div = document.createElement('div');
      var examples;

      beforeEach(function() {
        myp5 = null;
        myp5Div = null;
      });

      afterEach(function() {
        if (myp5) {
          myp5.remove();
        }
        if (myp5Div && myp5Div.parentNode) {
          myp5Div.parentNode.removeChild(myp5Div);
        }
      });

      div.style.display = 'none';
      div.innerHTML = info.example.join('');
      document.body.appendChild(div);
      examples = [].slice.call(div.querySelectorAll('div:not(.norender)'));

      examples.forEach(function(el, i) {
        var exampleCode = el.textContent
          .replace(/assets\//g, '../docs/reference/assets/');

        test("example #" + (i + 1) + " works", function(done) {
          var startTime = Date.now();

          this.timeout(MS_TIMEOUT);
          myp5Div = document.createElement('div');
          document.body.appendChild(myp5Div);

          myp5 = new p5(createExampleSketch(exampleCode, function(p) {
            var drawCalled = false;
            var oldDraw = p.draw || function() {};

            p.draw = function() {
              oldDraw.call(p);
              if (drawCalled) return;
              drawCalled = true;

              if (Date.now() - startTime > MS_TIMEOUT) {
                // This can happen if the page contained processor-intensive
                // code that blocked the UI for too long.
                return done(new Error("code took too long to execute"));
              }

              done();
            };
          }), myp5Div);
        });
      });
    });
  }<commit_msg>show example test code in doc tests.<commit_after><!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  <link rel="stylesheet" href="mocha.css"/>
  <style>
  iframe { visibility: hidden; }
  </style>
  <title>p5 Reference Documentation Test</title>
</head>
<body>
  <!-- Required for browser reporter -->
  <div id="mocha"></div>

  <!-- mocha -->
  <script src="js/mocha.js" type="text/javascript" ></script>
  <script type="text/javascript" >
    // This will be overridden by mocha-helper if you run with grunt
    mocha.setup('tdd');
    mocha.reporter('html');
  </script>

  <!-- Include your assertion lib of choice -->
  <script src="js/chai.js" type="text/javascript" ></script>
  <script src="js/bind.js" type="text/javascript" ></script>
  <script src="js/sinon.js" type="text/javascript" ></script>
  <script src="js/testRender.js" type="text/javascript" ></script>
  <script type="text/javascript" >
    // Setup chai
    var expect = chai.expect;
    var assert = chai.assert;
  </script>

  <!-- Include anything you want to test -->
  <script src="../lib/p5.js" type="text/javascript" ></script>
  <script src="../lib/addons/p5.dom.js" type="text/javascript" ></script>
  <script src="../lib/addons/p5.sound.js" type="text/javascript" ></script>

  <script>
  var MS_TIMEOUT = 2000;

  // TODO: This code has basically been harvested from
  // https://github.com/processing/p5.js-website/blob/master/js/render.js.
  // Ideally we should factor out this common code into a shared place
  // where we're not duplicating code.
  function createExampleSketch(exampleCode, cb) {
    var runnable = exampleCode.replace(/^\s+|\s+$/g, '');

    return function( p ) {
      if (runnable.indexOf('setup()') === -1 &&
          runnable.indexOf('draw()') === -1){
        p.setup = function() {
          p.createCanvas(100, 100);
          p.background(200);
          with (p) {
            eval(runnable);
          }
        }
      } else {
        with (p) {
          eval(runnable);
        }

        var fxns = [
          'setup', 'draw', 'preload', 'mousePressed', 'mouseReleased', 
          'mouseMoved', 'mouseDragged', 'mouseClicked', 'mouseWheel', 
          'touchStarted', 'touchMoved', 'touchEnded', 
          'keyPressed', 'keyReleased', 'keyTyped'
        ];
        fxns.forEach(function(f) { 
          var ind = runnable.indexOf(f+'(');
          // this is a gross hack within a hacky script that
          // ensures the function names found are not substrings
          // proper use of regex would be preferable...
          if (ind !== -1 && runnable[ind+f.length] === '(' &&
              eval('typeof ' + f) !== 'undefined') {
            with (p) {
              p[f] = eval(f);
            }
          }
        });
        if (typeof p.setup === 'undefined') {
          p.setup = function() {
            p.createCanvas(100, 100);
            p.background(200);
          }
        }
      }

      if (cb) {
        cb(p);
      }
    };
  }

  function defineTest(info) {
    suite(info.name + " documentation", function() {
      var myp5, myp5Div;
      var div = document.createElement('div');
      var examples;

      beforeEach(function() {
        myp5 = null;
        myp5Div = null;
      });

      afterEach(function() {
        if (myp5) {
          myp5.remove();
        }
        if (myp5Div && myp5Div.parentNode) {
          myp5Div.parentNode.removeChild(myp5Div);
        }
      });

      div.style.display = 'none';
      div.innerHTML = info.example.join('');
      document.body.appendChild(div);
      examples = [].slice.call(div.querySelectorAll('div:not(.norender)'));

      examples.forEach(function(el, i) {
        var exampleCode = el.textContent
          .replace(/assets\//g, '../docs/reference/assets/');

        var testFunc = function(done) {
          var startTime = Date.now();

          this.timeout(MS_TIMEOUT);
          myp5Div = document.createElement('div');
          document.body.appendChild(myp5Div);

          myp5 = new p5(createExampleSketch(exampleCode, function(p) {
            var drawCalled = false;
            var oldDraw = p.draw || function() {};

            p.draw = function() {
              oldDraw.call(p);
              if (drawCalled) return;
              drawCalled = true;

              if (Date.now() - startTime > MS_TIMEOUT) {
                // This can happen if the page contained processor-intensive
                // code that blocked the UI for too long.
                return done(new Error("code took too long to execute"));
              }

              done();
            };
          }), myp5Div);
        };

        testFunc.toString = function() {
          // When a user clicks on a specific test, mocha shows its
          // source code; in our case, we want the source of the example
          // we're running to be shown, *not* the example runner code.
          return exampleCode;
        };

        test("example #" + (i + 1) + " works", testFunc);
      });
    });
  }
{'fraction_non_alphanumeric': 0.15564400898142478, 'fraction_numerical': 0.00959379465196979, 'mean_word_length': 2.0049064704078505, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 81, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '324175', 'n_tokens_mistral': 3086, 'n_tokens_neox': 2960, 'n_words': 698}