diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b8b7013 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true + +[*.csproj] +indent_style = space +indent_size = 2 + +# CS1591: Missing XML comment for publicly visible type or member +dotnet_diagnostic.CS1591.severity = suggestion diff --git a/.gitattributes b/.gitattributes index 1ff0c42..5896c16 100644 --- a/.gitattributes +++ b/.gitattributes @@ -17,7 +17,7 @@ # # Merging from the command prompt will add diff markers to the files if there # are conflicts (Merging from VS is not affected by the settings below, in VS -# the diff markers are never inserted). Diff markers may cause the following +# the diff markers are never inserted). Diff markers may cause the following # file extensions to fail to load in VS. An alternative would be to treat # these files as binary and thus will always conflict and require user # intervention with every merge. To do so, just uncomment the entries below @@ -46,9 +46,9 @@ ############################################################################### # diff behavior for common document formats -# +# # Convert binary document formats to text before diffing them. This feature -# is only available from the command line. Turn it on by uncommenting the +# is only available from the command line. Turn it on by uncommenting the # entries below. ############################################################################### #*.doc diff=astextplain diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..2399534 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,18 @@ +# Contributor Covenant Code of Conduct + +This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. + +In particular this means: + +> We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery +* Personal attacks +* Trolling or insulting/derogatory comments +* Public or private harassment +* Publishing other's private information, such as physical or electronic addresses, without explicit permission +* Other unethical or unprofessional conduct + +For the complete set of rules and more information on the topic see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct). diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..f0a00c4 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,151 @@ +# Contributing + +## Project Scope + +The AngleSharp project ultimately tries to provide tools to parse, inspect, modify and interact with traditional web resources, such as HTML or CSS, for .NET development. Anything that is related to this goal will be considered. The project aims to be fully standards compliant. If your contribution is not following the standard, the chances of accepting it are limited. + +## Code License + +This is an open source project falling under the [MIT License](../LICENSE). By using, distributing, or contributing to this project, you accept and agree that all code within the AngleSharp project and its libraries are licensed under MIT license. + +## Becoming a Contributor + +Until the project has enough contributors a [BDFL](https://en.wikipedia.org/wiki/Benevolent_dictator_for_life) model is followed. As such the sole key maintainer keeps the right to appoint GitHub members as regular project contributors. Nevertheless, usually appointing someone follows this process: + +1. An individual contributes actively via discussions (reporting bugs, giving feedback to existing or opening new issues) and / or pull requests +2. The individual is either directly asked, invited or asks for contributor rights on the project +3. The individual uses the contribution rights to sustain or increase the active contributions + +Every contributor has to sign the contributor's license agreement (CLA) to establish a legal trust between the project and its contributors. + +## Working on AngleSharp + +### Issue Discussion + +Discussion of issues should be placed transparently in the issue tracker here on GitHub. + +* [AngleSharp.Core](https://github.com/AngleSharp/AngleSharp/issues/) +* [AngleSharp.Css](https://github.com/AngleSharp/AngleSharp.Css/issues/) +* [AngleSharp.Io](https://github.com/AngleSharp/AngleSharp.Io/issues/) +* [AngleSharp.Js](https://github.com/AngleSharp/AngleSharp.Js/issues/) +* [AngleSharp.Xml](https://github.com/AngleSharp/AngleSharp.Xml/issues/) + +### Modifying the code + +AngleSharp and its libraries uses features from the latest versions of C# (e.g., C# 7). You will therefore need a C# compiler that is up for the job. + +1. Fork and clone the repo. +2. First try to build the AngleSharp.Core libray and see if you get the tests running. +3. You will be required to resolve some dependencies via NuGet. + +AngleSharp itself does not have dependencies, however, the tests are dependent on NUnit. + +The build system of AngleSharp uses Cake. A bootstrap script (build.ps1 for Windows or build.sh for *nix systems) is included. Note, that at the moment AngleSharp may require NuGet 3.5, which looks for MSBuild pre-15, i.e., before Visual Studio 2017 on Windows systems. We aim to drop this requirement enitirely soon. + +### Code Conventions + +Most parts in the AngleSharp project are fairly straight forward. Among these are: + +- Always use statement blocks for control statements, e.g., in a for-loop, if-condition, ... +- You may use a simple (throw) statement in case of enforcing contracts on argument +- Be explicit about modifiers (some files follow an older convention of the code base, but we settled on the explicit style) + +There are a couple of rules, which are definitely not standard, but highly recommended for consistency and readability: + +- AngleSharp uses the RHS convention, where types are always put on the right hand side if possible, i.e., preferring `var` under all circumstances +- A single empty line between two non-simple statements (e.g., for-loop and if-condition) should be inserted +- Types are preferred to keywords (`String` instead of `string` or `Int32` instead of `int`) +- `using` statements must be inside the namespace declaration + +### Development Workflow + +1. If no issue already exists for the work you'll be doing, create one to document the problem(s) being solved and self-assign. +2. Otherwise please let us know that you are working on the problem. Regular status updates (e.g. "still in progress", "no time anymore", "practically done", "pull request issued") are highly welcome. +2. Create a new branch—please don't work in the `master` branch directly. It is reserved for releases. We recommend naming the branch to match the issue being addressed (`feature/#777` or `issue-777`). +3. Add failing tests for the change you want to make. Tests are crucial and should be taken from W3C (or other specification). +4. Fix stuff. Always go from edge case to edge case. +5. All tests should pass now. Also your new implementation should not break existing tests. +6. Update the documentation to reflect any changes. (or document such changes in the original issue) +7. Push to your fork or push your issue-specific branch to the main repository, then submit a pull request against `devel`. + +Just to illustrate the git workflow for AngleSharp a little bit more we've added the following graphs. + +Initially, AngleSharp starts at the `master` branch. This branch should contain the latest stable (or released) version. + +Here we now created a new branch called `devel`. This is the development branch. + +Now active work is supposed to be done. Therefore a new branch should be created. Let's create one: + +``` +git checkout -b feature/#777 +``` + +There may be many of these feature branches. Most of them are also pushed to the server for discussion or synchronization. + +``` +git push -u origin feature/#777 +``` + +Now feature branches may be closed when they are done. Here we simply merge with the feature branch(es). For instance the following command takes the `feature/#777` branch from the server and merges it with the `devel` branch. + +``` +git checkout devel +git pull +git pull origin feature/#777 +git push +``` + +Finally, we may have all the features that are needed to release a new version of AngleSharp. Here we tag the release. For instance for the 1.0 release we use `v1.0`. + +``` +git checkout master +git merge devel +git tag v1.0 +``` + +(The last part is automatically performed by our CI system.) + +### Basic Files + +The following files should not be edited directly in the current repository, but rather in the `AngleSharp.GitBase` repository. They are then synced via `git pull` from a different remote. + +``` +.editorconfig +.gitignore +.gitattributes +.github/* +appveyor.yml +build.ps1 +build.sh +tools/anglesharp.cake +tools/packages.config +LICENSE +``` + +To sync manually: + +``` +git remote add gitbase git@github.com:AngleSharp/AngleSharp.GitBase.git +git pull gitbase master +``` + +### Versioning + +The rules of [semver](http://semver.org/) don't necessarily apply here, but we will try to stay quite close to them. + +Prior to version 1.0.0 we use the following scheme: + +1. MINOR versions for reaching a feature milestone potentially combined with dramatic API changes +2. PATCH versions for refinements (e.g. performance improvements, bug fixes) + +After releasing version 1.0.0 the scheme changes to become: + +1. MAJOR versions at maintainers' discretion following significant changes to the codebase (e.g., API changes) +2. MINOR versions for backwards-compatible enhancements (e.g., performance improvements) +3. PATCH versions for backwards-compatible bug fixes (e.g., spec compliance bugs, support issues) + +#### Code style + +Regarding code style like indentation and whitespace, **follow the conventions you see used in the source already.** In general most of the [C# coding guidelines from Microsoft](https://msdn.microsoft.com/en-us/library/ff926074.aspx) are followed. This project prefers type inference with `var` to explicitly stating (redundant) information. + +It is also important to keep a certain `async`-flow and to always use `ConfigureAwait(false)` in conjunction with an `await` expression. diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..44871a9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,39 @@ +--- +name: Bug Report +about: Create a report to help us improve +title: '' +labels: 'bug' +assignees: '' +--- + +# Bug Report + +## Prerequisites + +- [ ] Can you reproduce the problem in a [MWE](https://en.wikipedia.org/wiki/Minimal_working_example)? +- [ ] Are you running the latest version of AngleSharp? +- [ ] Did you check the FAQs to see if that helps you? +- [ ] Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g., `AngleSharp.Css` for CSS support) +- [ ] Did you perform a search in the issues? + +For more information, see the `CONTRIBUTING` guide. + +## Description + +[Description of the bug] + +## Steps to Reproduce + +1. [First Step] +2. [Second Step] +3. [and so on...] + +**Expected behavior:** [What you expected to happen] + +**Actual behavior:** [What actually happened] + +**Environment details:** [OS, .NET Runtime, ...] + +## Possible Solution + +[Optionally, share your idea to fix the issue] diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..7722f05 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,21 @@ +--- +name: Feature Request +about: Suggest an idea for this project +title: '' +labels: 'enhancement' +assignees: '' +--- + +# New Feature Proposal + +## Description + +[Description of the proposed feature] + +## Background + +Provide any additional background for the feature. e.g., user scenarios. + +## Specification + +In case of updates that adhere to specification changes, please reference the used specification. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..f3f3c41 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,24 @@ +# Types of Changes + +## Prerequisites + +Please make sure you can check the following two boxes: + +- [ ] I have read the **CONTRIBUTING** document +- [ ] My code follows the code style of this project + +## Contribution Type + +What types of changes does your code introduce? Put an `x` in all the boxes that apply: + +- [ ] Bug fix (non-breaking change which fixes an issue, please reference the issue id) +- [ ] New feature (non-breaking change which adds functionality, make sure to open an associated issue first) +- [ ] Breaking change (fix or feature that would cause existing functionality to change) +- [ ] My change requires a change to the documentation +- [ ] I have updated the documentation accordingly +- [ ] I have added tests to cover my changes +- [ ] All new and existing tests passed + +## Description + +[Place a meaningful description here.] diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml deleted file mode 100644 index 33775b0..0000000 --- a/.github/workflows/CI.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: CI - -on: - push: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Setup .NET core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 3.0.100 - - name: Build with dotnet - run: dotnet build --configuration Release - - name: Run unit tests - run: dotnet test diff --git a/.gitignore b/.gitignore index 4ce6fdd..e87b082 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,13 @@ bld/ [Oo]bj/ [Ll]og/ +[Pp]ackages/ +[Tt]ools/ +![Tt]ools/packages.config +*.nuget.targets +*.nuget.props +*.nupkg + # Visual Studio 2015/2017 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot @@ -337,4 +344,6 @@ ASALocalRun/ .localhistory/ # BeatPulse healthcheck temp database -healthchecksdb \ No newline at end of file +healthchecksdb + +*.ncrunchsolution \ No newline at end of file diff --git a/AngleSharp.Diffing.v3.ncrunchsolution b/AngleSharp.Diffing.v3.ncrunchsolution deleted file mode 100644 index 10420ac..0000000 --- a/AngleSharp.Diffing.v3.ncrunchsolution +++ /dev/null @@ -1,6 +0,0 @@ - - - True - True - - \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..4506815 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# 0.13.0-preview-1 + +Released on Sunday, November 3, 2019. + +This is the initial preview release of AngleSharp.Diffing. diff --git a/Directory.Build.props b/Directory.Build.props deleted file mode 100644 index fe17791..0000000 --- a/Directory.Build.props +++ /dev/null @@ -1,11 +0,0 @@ - - - 8.0 - enable - CS8600;CS8602;CS8603;CS8625 - - - 0.13.0 - 2.9.6 - - \ No newline at end of file diff --git a/README.md b/README.md index a0b451e..68aa0f0 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,22 @@ +![AngleSharp Diffing](/docs/header.png) # AngleSharp Diffing - A diff/compare library for AngleSharp -This library makes it possible to compare a AngleSharp _control_ `INodeList` and a _test_ `INodeList` and get a list of `IDiff` differences between them. +[![Build status](https://ci.appveyor.com/api/projects/status/8awr3r4ylwy9habm?svg=true)](https://ci.appveyor.com/project/FlorianRappl/anglesharp-diffing) +[![GitHub Tag](https://img.shields.io/github/tag/AngleSharp/AngleSharp.Diffing.svg?style=flat-square)](https://github.com/AngleSharp/AngleSharp.Diffing/releases) +[![NuGet Count](https://img.shields.io/nuget/dt/AngleSharp.Diffing.svg?style=flat-square)](https://www.nuget.org/packages/AngleSharp.Diffing/) +[![Issues Open](https://img.shields.io/github/issues/AngleSharp/AngleSharp.Diffing.svg?style=flat-square)](https://github.com/AngleSharp/AngleSharp.Diffing/issues) +[![Gitter Chat](http://img.shields.io/badge/gitter-AngleSharp/AngleSharp-blue.svg?style=flat-square)](https://gitter.im/AngleSharp/AngleSharp) +[![StackOverflow Questions](https://img.shields.io/stackexchange/stackoverflow/t/anglesharp.svg?style=flat-square)](https://stackoverflow.com/tags/anglesharp) +[![CLA Assistant](https://cla-assistant.io/readme/badge/AngleSharp/AngleSharp.Diffing?style=flat-square)](https://cla-assistant.io/AngleSharp/AngleSharp.Diffing) + +AngleSharp Diffing makes it possible to compare AngleSharp _control_ nodes and _test_ nodes and get a list of differences between them. The _control_ nodes represents the expected HTML tree, i.e. how the nodes are expected to look, and the _test_ nodes represents the nodes that should be compared to the _control_ nodes. **Differences:** There are three types off `IDiff` differences, that the library can return. -- `Diff`/`AttrDiff`: Represents a difference between a control and test node or a control and test attribute. -- `MissingDiff`/`MissingAttrDiff`: Represents a difference where a control node or control attribute was expected to exist, but was not found in the test nodes tree. -- `UnexpectedDiff`/`UnexpectedAttrDiff`: Represents a difference where a test node or test attribute was unexpectedly found in the test nodes tree, but did not have a match in the control nodes tree. +- `NodeDiff`/`AttrDiff`: Represents a difference between a control and test node or a control and test attribute. +- `MissingNodeDiff`/`MissingAttrDiff`: Represents a difference where a control node or control attribute was expected to exist, but was not found in the test nodes tree. +- `UnexpectedNodeDiff`/`UnexpectedAttrDiff`: Represents a difference where a test node or test attribute was unexpectedly found in the test nodes tree, but did not have a match in the control nodes tree. # Usage To find the differences between a control HTML fragment and a test HTML fragment, using the default options, the easiest way is to use the `DiffBuilder` class, like so: @@ -16,17 +25,16 @@ To find the differences between a control HTML fragment and a test HTML fragment var controlHtml = "

Hello World

"; var testHtml = "

World, I say hello

"; var diffs = DiffBuilder - .Compare(controlHtml) - .WithTest(testHtml) - .WithDefaultOptions() + .Compare(control) + .WithTest(test) .Build(); ``` -Read more about the available options on the [Diffing Options/Strategies](/docs/Strategies.md) page. +Read more about the available options on the [Options](/docs/Options.md) page. # Documentation -- [Diffing Options/Strategies](/docs/Strategies.md) -- [Creating custom diffing options/strategies](/docs/CustomStrategies.md) +- [Options](/docs/Options.md) +- [Creating custom diffing options](/docs/CustomOptions.md) - [Difference engine internals](/docs/DiffingEngineInternals.md) ## Acknowledgments diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..7f7d081 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,20 @@ +version: '{build}' +branches: + only: + - master + - dev +skip_tags: true +image: Visual Studio 2019 +configuration: Release +platform: Any CPU +build_script: +- ps: >- + if ($env:APPVEYOR_PULL_REQUEST_NUMBER -eq $null -and $env:APPVEYOR_REPO_BRANCH -eq "master") { + .\build.ps1 -Target Publish + } elseif ($env:APPVEYOR_PULL_REQUEST_NUMBER -eq $null -and $env:APPVEYOR_REPO_BRANCH -eq "dev") { + .\build.ps1 -Target PrePublish + } else { + .\build.ps1 -Target AppVeyor + } +test: off +deploy: off diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..a2de43c --- /dev/null +++ b/build.cake @@ -0,0 +1,11 @@ +var target = Argument("target", "Default"); +var projectName = "AngleSharp.Diffing"; +var solutionName = "AngleSharp.Diffing"; +var frameworks = new Dictionary +{ + { "netstandard2.0", "netstandard2.0" }, +}; + +#load tools/anglesharp.cake + +RunTarget(target); \ No newline at end of file diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..61a9f11 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,81 @@ +Param( + [string]$Script = "build.cake", + [string]$Target = "Default", + [ValidateSet("Release", "Debug")] + [string]$Configuration = "Release", + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity = "Verbose", + [switch]$Experimental, + [switch]$WhatIf, + [switch]$Mono, + [switch]$SkipToolPackageRestore, + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$ScriptArgs +) + +$PSScriptRoot = split-path -parent $MyInvocation.MyCommand.Definition; +$UseDryRun = ""; +$UseMono = ""; +$TOOLS_DIR = Join-Path $PSScriptRoot "tools" +$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe" +$NUGET_OLD_EXE = Join-Path $TOOLS_DIR "nuget_old.exe" +$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe" +$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +$NUGET_OLD_URL = "https://dist.nuget.org/win-x86-commandline/v3.5.0/nuget.exe" + +# Should we use experimental build of Roslyn? +$UseExperimental = ""; +if ($Experimental.IsPresent) { + $UseExperimental = "-experimental" +} + +# Is this a dry run? +if ($WhatIf.IsPresent) { + $UseDryRun = "-dryrun" +} + +# Should we use mono? +if ($Mono.IsPresent) { + $UseMono = "-mono" +} + +# Try download NuGet.exe if do not exist. +if (!(Test-Path $NUGET_EXE)) { + (New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE) +} + +# Try download NuGet.exe if do not exist. +if (!(Test-Path $NUGET_OLD_URL)) { + (New-Object System.Net.WebClient).DownloadFile($NUGET_OLD_URL, $NUGET_OLD_EXE) +} + +# Make sure NuGet (latest) exists where we expect it. +if (!(Test-Path $NUGET_EXE)) { + Throw "Could not find nuget.exe" +} + +# Make sure NuGet (v3.5.0) exists where we expect it. +if (!(Test-Path $NUGET_OLD_EXE)) { + Throw "Could not find nuget_old.exe" +} + +# Restore tools from NuGet? +if (-Not $SkipToolPackageRestore.IsPresent) +{ + Push-Location + Set-Location $TOOLS_DIR + Invoke-Expression "$NUGET_EXE install -ExcludeVersion" + Pop-Location + if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE + } +} + +# Make sure that Cake has been installed. +if (!(Test-Path $CAKE_EXE)) { + Throw "Could not find Cake.exe" +} + +# Start Cake +Invoke-Expression "$CAKE_EXE `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs" +exit $LASTEXITCODE \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..41923b4 --- /dev/null +++ b/build.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +############################################################### +# This is the Cake bootstrapper script that is responsible for +# downloading Cake and all specified tools from NuGet. +############################################################### + +# Define directories. +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +TOOLS_DIR=$SCRIPT_DIR/tools +NUGET_EXE=$TOOLS_DIR/nuget.exe +NUGET_OLD_EXE=$TOOLS_DIR/nuget_old.exe +CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe + +# Define default arguments. +SCRIPT="build.cake" +TARGET="Default" +CONFIGURATION="Release" +VERBOSITY="verbose" +DRYRUN= +SHOW_VERSION=false +SCRIPT_ARGUMENTS=() + +# Parse arguments. +for i in "$@"; do + case $1 in + -s|--script) SCRIPT="$2"; shift ;; + -t|--target) TARGET="$2"; shift ;; + -c|--configuration) CONFIGURATION="$2"; shift ;; + -v|--verbosity) VERBOSITY="$2"; shift ;; + -d|--dryrun) DRYRUN="-dryrun" ;; + --version) SHOW_VERSION=true ;; + --) shift; SCRIPT_ARGUMENTS+=("$@"); break ;; + *) SCRIPT_ARGUMENTS+=("$1") ;; + esac + shift +done + +# Make sure the tools folder exist. +if [ ! -d $TOOLS_DIR ]; then + mkdir $TOOLS_DIR +fi + +# Make sure that packages.config exist. +if [ ! -f $TOOLS_DIR/packages.config ]; then + echo "Downloading packages.config..." + curl -Lsfo $TOOLS_DIR/packages.config http://cakebuild.net/bootstrapper/packages + if [ $? -ne 0 ]; then + echo "An error occured while downloading packages.config." + exit 1 + fi +fi + +# Download NuGet (v3.5.0) if it does not exist. +if [ ! -f $NUGET_OLD_EXE ]; then + echo "Downloading NuGet..." + curl -Lsfo $NUGET_OLD_EXE https://dist.nuget.org/win-x86-commandline/v3.5.0/nuget.exe + if [ $? -ne 0 ]; then + echo "An error occured while downloading nuget.exe." + exit 1 + fi +fi + +# Download NuGet (latest) if it does not exist. +if [ ! -f $NUGET_EXE ]; then + echo "Downloading NuGet..." + curl -Lsfo $NUGET_EXE https://dist.nuget.org/win-x86-commandline/latest/nuget.exe + if [ $? -ne 0 ]; then + echo "An error occured while downloading nuget.exe." + exit 1 + fi +fi + +# Restore tools from NuGet. +pushd $TOOLS_DIR >/dev/null +mono $NUGET_EXE install -ExcludeVersion +if [ $? -ne 0 ]; then + echo "Could not restore NuGet packages." + exit 1 +fi +popd >/dev/null + +# Make sure that Cake has been installed. +if [ ! -f $CAKE_EXE ]; then + echo "Could not find Cake.exe at '$CAKE_EXE'." + exit 1 +fi + +# Start Cake +if $SHOW_VERSION; then + exec mono $CAKE_EXE -version +else + exec mono $CAKE_EXE $SCRIPT -verbosity=$VERBOSITY -configuration=$CONFIGURATION -target=$TARGET $DRYRUN "${SCRIPT_ARGUMENTS[@]}" +fi \ No newline at end of file diff --git a/docs/CustomStrategies.md b/docs/CustomOptions.md similarity index 96% rename from docs/CustomStrategies.md rename to docs/CustomOptions.md index 244fe1b..13b5681 100644 --- a/docs/CustomStrategies.md +++ b/docs/CustomOptions.md @@ -1,7 +1,5 @@ # Creating custom diffing strategies -TODO! - ### Filters - default starting decision is `true`. - if a filter receives a source that it does not have an opinion on, it should always return the current decision, whatever it may be. \ No newline at end of file diff --git a/docs/Strategies.md b/docs/Options.md similarity index 76% rename from docs/Strategies.md rename to docs/Options.md index 41cdb39..8069bbc 100644 --- a/docs/Strategies.md +++ b/docs/Options.md @@ -1,4 +1,4 @@ -# Diffing options/strategies: +# Diffing Options The library comes with a bunch of options (internally referred to as strategies), for the following three main steps in the diffing process: 1. Filtering out irrelevant nodes and attributes @@ -7,14 +7,12 @@ The library comes with a bunch of options (internally referred to as strategies) To make it easier to configure the diffing engine, the library comes with a `DiffBuilder` class, which handles the relative complex task of setting up the `HtmlDifferenceEngine`. -Using the `UseDefaultOptions()` method is equivalent to setting the following options explicitly: - -To learn how to create your own strategies, visit the [Custom Strategies](CustomStrategies.md) page. +To learn how to create your own strategies, visit the [Custom Options](CustomOptions.md) page. The following section documents the current built-in strategies that are available. ## Default Options -In most cases, calling the `UseDefaultOptions()` method on a `DiffBuilder` instance will give you a good set of strategies for a comparison, e.g. +In most cases, calling `DiffBuilder.Compare(...).WithTest(...).Build()` will give you a good set of default options for a comparison, e.g. ```csharp var controlHtml = "

Hello World

"; @@ -22,29 +20,42 @@ var testHtml = "

World, I say hello

"; var diffs = DiffBuilder .Compare(controlHtml) .WithTest(testHtml) - .WithDefaultOptions() .Build(); ``` -Calling the `WithDefaultOptions()` method is equivalent to specifying the following options explicitly: +If you want to be more explicit, the following is equivalent to the code above: + +```csharp +var controlHtml = "

Hello World

"; +var testHtml = "

World, I say hello

"; +var diffs = DiffBuilder + .Compare(control) + .WithTest(test) + .WithOptions((IDiffingStrategyCollection options) => options.AddDefaultOptions()) + .Build(); +``` + +Calling the `AddDefaultOptions()` method is equivalent to specifying the following options explicitly: ```csharp var diffs = DiffBuilder .Compare(controlHtml) .WithTest(testHtml) - .IgnoreDiffAttributes() - .IgnoreComments() - .WithSearchingNodeMatcher() - .WithCssSelectorMatcher() - .WithAttributeNameMatcher() - .WithNodeNameComparer() - .WithIgnoreElementSupport() - .WithStyleSheetComparer() - .WithTextComparer(WhitespaceOption.Normalize, ignoreCase: false) - .WithAttributeComparer() - .WithClassAttributeComparer() - .WithBooleanAttributeComparer(BooleanAttributeComparision.Strict) - .WithStyleAttributeComparer() + .WithOptions((IDiffingStrategyCollection options) => options + .IgnoreDiffAttributes() + .IgnoreComments() + .AddSearchingNodeMatcher() + .AddCssSelectorMatcher() + .AddAttributeNameMatcher() + .AddElementComparer() + .AddIgnoreElementSupport() + .AddStyleSheetComparer() + .AddTextComparer(WhitespaceOption.Normalize, ignoreCase: false) + .AddAttributeComparer() + .AddClassAttributeComparer() + .AddBooleanAttributeComparer(BooleanAttributeComparision.Strict) + .AddStyleAttributeComparer() + ) .Build(); ``` @@ -54,28 +65,49 @@ Read more about each of the strategies below, including some that are not part o These are the built-in filter strategies. ### Ignore comments -Enabling this strategy will ignore all comment nodes during comparison. Activate by calling the `IgnoreComments()` method on a `DiffBuilder` instance, e.g.: +Enabling this strategy will ignore all comment nodes during comparison. Activate by calling the `IgnoreComments()` method on a `IDiffingStrategyCollection` type, e.g.: ```csharp var diffs = DiffBuilder .Compare(controlHtml) .WithTest(testHtml) - .IgnoreComments() + .WithOptions(options => options.IgnoreComments()) .Build(); ``` _**NOTE**: Currently, the ignore comment strategy does NOT remove comments from CSS or JavaScript embedded in `