===
navigate to test page
%require
===
plwr -S plwr-test open "http://localhost:8599/index.html"
---

===
eval returns a string
===
plwr -S plwr-test eval "document.title"
---
plwr test

===
eval returns a number
===
plwr -S plwr-test eval "1 + 2"
---
3

===
eval returns structured JSON object
===
plwr -S plwr-test eval "({a: 1, b: [2, 3]})"
---
{
  "a": 1,
  "b": [
    2,
    3
  ]
}

===
eval returns a JSON array
===
plwr -S plwr-test eval "[1, 'two', null]"
---
[
  1,
  "two",
  null
]

===
eval can access DOM
===
plwr -S plwr-test eval "document.querySelector('h1').textContent"
---
Test Page

===
eval returns boolean true (exit 0, no output)
===
plwr -S plwr-test eval "document.querySelectorAll('p').length > 0"
---

===
eval returns boolean false (exit 1, no output)
===
! plwr -S plwr-test eval "document.querySelectorAll('.nope').length > 0"
---

===
eval returns null
===
plwr -S plwr-test eval "null"
---

===
eval IIFE: multi-statement logic returning an array
===
plwr -S plwr-test eval "(() => {
  const items = document.querySelectorAll('p');
  return Array.from(items).map(el => el.textContent);
})()"
---
[
  "First paragraph",
  "Second paragraph"
]

===
eval IIFE: collect DOM info into an object
===
plwr -S plwr-test eval "(() => {
  const h1 = document.querySelector('h1');
  return {
    tag: h1.tagName,
    text: h1.textContent,
    childCount: h1.childNodes.length
  };
})()"
---
{
  "childCount": 1,
  "tag": "H1",
  "text": "Test Page"
}

===
eval IIFE: walk parent chain with computed styles
===
plwr -S plwr-test eval "(() => {
  const el = document.querySelector('p');
  let node = el;
  const chain = [];
  while (node && chain.length < 3) {
    const cs = getComputedStyle(node);
    chain.push({
      tag: node.tagName,
      display: cs.display
    });
    node = node.parentElement;
  }
  return chain;
})()"
---
[
  {
    "display": "block",
    "tag": "P"
  },
  {
    "display": "block",
    "tag": "BODY"
  },
  {
    "display": "block",
    "tag": "HTML"
  }
]

===
eval IIFE: filter and map table-like data
===
plwr -S plwr-test eval "(() => {
  const links = document.querySelectorAll('a');
  return Array.from(links).map(a => ({
    text: a.textContent,
    href: a.getAttribute('href')
  }));
})()"
---
[
  {
    "href": "/form.html",
    "text": "Form"
  }
]
